Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2004, 05:36 PM   PM User | #1
MPCODER
New Coder

 
Join Date: Jan 2004
Location: The Netherlands
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
MPCODER is an unknown quantity at this point
Is there a scipt that logs IP adresses of visitors in a .TXT File?

Hello,
I really wanna know a php script that logs the ip adresses of visitors into a .TXT file on the website. I searched around these forums and tried the search engine but didn't found what i wanted. Please help me.
MPCODER is offline   Reply With Quote
Old 01-03-2004, 05:46 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
PHP Code:
<?php
$file 
"iplog.txt";
$ip $_SERVER['REMOTE_ADDR'];

if(
is_writable($file)){
  
$open fopen($file,"a");
  
fwrite($open,$ip);
  
fclose($open);
}else{
  
chmod($file,0777) or die("Attempted to chmod the file, it was unsuccessful, please chmod ".$file." to 0777 yourself");
  echo 
'File was unwritable. Please refresh the page to try again';
}
?>
Put that at the top of the page you want to log the ip's on
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks

Last edited by Nightfire; 01-03-2004 at 05:49 PM..
Nightfire is offline   Reply With Quote
Old 01-03-2004, 06:09 PM   PM User | #3
MPCODER
New Coder

 
Join Date: Jan 2004
Location: The Netherlands
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
MPCODER is an unknown quantity at this point
Thanks! but i also found this:
PHP Code:
?php 

$filename
"hits.txt" 

$fd fopen ($filename "r") or die ("Uhoh! The PHP script cant open $filename") ; 

$fstring fread ($fd filesize ($filename)) ; 

echo 
"$fstring" 

fclose($fd) ; 



$fd fopen ($filename "w") or die ("Uhoh! The PHP script cant open $filename") ; 

$fcounted $fstring 

$foutfwrite ($fd $fcounted ) ; 

fclose($fd) ; 

?> 
MPCODER is offline   Reply With Quote
Old 01-03-2004, 06:11 PM   PM User | #4
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
Well that's not logging IP's of visitors, that's a hit counter.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 01-03-2004, 06:14 PM   PM User | #5
MPCODER
New Coder

 
Join Date: Jan 2004
Location: The Netherlands
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
MPCODER is an unknown quantity at this point
Unhappy Welllll

Then i got the wrong code from a guy. I had my doubts already, for not containing REMOTE_ADDR thing.
MPCODER is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:51 AM.


Advertisement
Log in to turn off these ads.