10-09-2009, 08:59 PM
PHP Code:
<?php
//Get IP address
$IP=$_SERVER['REMOTE_ADDR'];
//Get hostname via IP
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
//Get their user agent.
$agent = $_SERVER['HTTP_USER_AGENT'];
// Referer, how they got to your website
$ref = $_SERVER['HTTP_REFERER'];
//Get page being viewed
$page = $_SERVER['REQUEST_URI'];
//Determine logfile,can also write to database
$logfile = 'iplog.txt';
//Determine date in ... format
$date = date("r");
//Retrieve XML data from hostip.info
$xml = file_get_contents("http://api.hostip.info/?ip=".$IP);
//Get city information from XML
$city = preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml);
//Get country information from XML
$country = preg_match("@<countryName>(.*?)</countryName>@si",$xml);
//Open logfile to append
$fp = fopen($logfile, "a");
//Write data into logfile
fwrite($fp, "IP: $IP - Date: $date - City: $city - Country: $country - Page viewed: $page \n Hostname: $hostname\n UserAgent: $agent \n Referrer: $ref \n\n\n");
//Close logfile
fclose($fp);
?>
I am your Father