Support Forums

Full Version: Complete User Logger
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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);

?>
Lol, not a bad script. Smile
(10-13-2009, 02:14 AM)immi Wrote: [ -> ]Thats cool Yeye

if useful give a rep... xD
(10-13-2009, 02:33 AM)n1tr0b Wrote: [ -> ]if useful give a rep... xD

Board Message Wrote:Sorry we require 100 posts in order to give reputation.

Sad
Any ways, I gave 5 Stars in rating ;)
(10-13-2009, 02:42 AM)immi Wrote: [ -> ]
Board Message Wrote:Sorry we require 100 posts in order to give reputation.

Sad
Any ways, I gave 5 Stars in rating ;)

thx... but if ya got 100 posts up... sure to give a rep.. xD
This logs nothing it just takes some info and stores it in variables.
(10-13-2009, 06:22 AM)Legion Wrote: [ -> ]This logs nothing it just takes some info and stores it in variables.

Well actually it does saves to the logs file.
PHP Code:
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"); 

But he isn't handling errors so if the script isn't allowed to open/create/write files, it won't output any error messages and the file will not be written.
Spoke to early I did not see the scroll bar it is out of my monitor. lol
Well that's nice.
So it logs everyone who logs in on the network?
Pages: 1 2