Logging Website Visitor Information
Every one needs to promote their website. So we takes care on the content, designing ,etc… after launching our site we will start getting more hits everyday. But we have to trace all the hits. We must log the visitors ip address and referrer address alltime. Because someone may try to attack your server based on url. Just log the details everytime. It will be fine for you.
Step 1:
Include the below code in your footer.php or in footer or header area of all of your pages.
$remote = $_SERVER[’REMOTE_ADDR’];
$remote .= “–”;
$remote .= $_SERVER[’HTTP_REFERER’];
$date = date(”d-n-Y”);
$remote .= “– “;
$remote .= $date;
$remote .= “\r\n”;
$filename = ‘home.txt’;
if (is_writable($filename))
{
// In our example we’re opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that’s where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, ‘a’))
{
// echo “Cannot open file ($filename)”;
exit;
} // Write $somecontent to our opened file.
if (fwrite($handle, $remote) === FALSE)
{
// echo “Cannot write to file ($filename)”;
exit;
}
//echo “Success, wrote ($remote) to file ($filename)”;
fclose($handle);}
else
{
//echo “The file $filename is not writable”;
}
If you like to see the script’s status then just remove the comment lines.
Step 2:
Create a text file named home.txt and chmod it to 0777
We are just writing information in to a file using php. Just do the above two steps and start logging your visitors.
























You must be logged in to post a comment.