Wednesday, May 30, 2012

Get Visitors IP Address PHP


Get Visitors IP Address PHP

 web statistic is very important when you start  your own site.web statistics mainly consist of page views today,yesterday,last month &all history etc.in addition to those some applications have IP addresses of viewers display.In this post I show you how to collect Ip address of your page viewers and store in a text file.
                                           First you have to make empty  text file called "visitor.txt" in your web root. where store IP Addresses of visitors.
           Following PHP File track the visitors IP address and store in above text file.
<?php
$counter = "visitor.txt";
$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];
$current_date = $mday . $month . $year;
$fp = fopen($counter, "a");
$line = $REMOTE_ADDR . "|" . $mday . $month . $year . "\n";
$size = strlen($line);
fputs($fp, $line, $size);
fclose($fp);
echo "IP Address: " . $_SERVER['REMOTE_ADDR'] . "<br>"; // Display IP address
echo "Referrer: " . $_SERVER['HTTP_REFERER'] . "<br>"; // Display the referrer
echo "Browser: " . $_SERVER['HTTP_USER_AGENT'] . ""; // Display browser type
?>

No comments:

Post a Comment