...

View Full Version : Is there a scipt that logs IP adresses of visitors in a .TXT File?



MPCODER
01-03-2004, 05:36 PM
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.

Nightfire
01-03-2004, 05:46 PM
<?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

MPCODER
01-03-2004, 06:09 PM
Thanks! but i also found this:

?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 + 1 ;

$fout= fwrite ($fd , $fcounted ) ;

fclose($fd) ;

?>

Nightfire
01-03-2004, 06:11 PM
Well that's not logging IP's of visitors, that's a hit counter.

MPCODER
01-03-2004, 06:14 PM
Then i got the wrong code from a guy. I had my doubts already, for not containing REMOTE_ADDR thing.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum