Click to See Complete Forum and Search --> : Ip Logging With PHP


giggledesign
12-08-2003, 03:29 PM
I am trying to set up an IP logging PHP code:

This is a code i have stumbled accross.

<?
$log_file = "ip.txt";
$hourdiff = "-8";
$timeadjust = ($hourdiff * 60 * 60);
$date = date("l, d F Y \t h:i a",time() + $timeadjust);
$ie = getenv('HTTP_USER_AGENT');
$ip = getenv('REMOTE_ADDR');
$ia = $_SERVER["HTTP_REFERER"];
$fp = fopen("$log_file", "a");
fputs($fp, "$iprn");
flock($fp, 3);
fwrite($fp,$date);
fwrite($fp,"\t");
fwrite($fp,$ip);
fwrite($fp,"\t\t");
fwrite($fp,$ie);
fwrite($fp,"\t");
fwrite($fp,$ia);
fwrite($fp,"\n");
fclose($fp);
PRINT("Your Ip was logged $ip <br>");
?>



the problem is, if you look at
http://www.giggledesign.com/home/iplog.php


you will see that it wont work. i don't know what to do.
can anyone help please?

Pittimann
12-08-2003, 05:55 PM
Hi!

Seems, your problem is not getting the ip, but writing it to "ip.txt".

Either the path "ip.txt" (assigned to $log_file) is not correct, the file does not exist (I would assume that) or you didn't give yourself/ the user the right to write to that file...

Cheers - Pit

Paul Jr
12-08-2003, 08:52 PM
This code was posted in another post, so I nabbed it.
If the file "ip.txt" does not exist, it will be created automatically, and that's where the IP's will be posted. I didn't have any trouble using the bit of code myself.