Monday, August 24, 2009

Anatomy of a simple IP logger in php

Share Orkut


// IP logger, place file at

//This picture variable defines which image to show
$picture = "";

//Visitor's IP address is stored in the variable '$ip'

//this line tells the logger the name you want to use for the log file.
// if log.txt doesn't already exist, it will be created automatically
$logs = "log.txt";

//here, we open the log.txt for writing to. The 'a' means append to the EOF
$fh = fopen($logs, 'a') or die(" ");

//here we put the ip address into a variable called 'string data'
// the backslash-n starts a new line in the text file, to make it easier to read
$stringData = "$ip \n";

//here we write to the text file what is in the stringdata variable
fwrite($fh, $stringData);

//now we close the file

//and finally we echo some html back to the user's browser so they see an image
echo "<img src='$picture'>";



If you want to learn web technologies, is a pretty good website.


Post a Comment

Write your comment here