Search This Blog

Monday, July 25, 2011

Using php to display visitor / user information such as their IP address

$ip = $_SERVER['REMOTE_ADDR'];
$hostaddress = gethostbyaddr($ip);
$browser = $_SERVER['HTTP_USER_AGENT'];
$referred = $_SERVER['HTTP_REFERER']; // a quirky spelling mistake that stuck in php

print "Display IP address:
\n";
print "$ip

\n";
print "More detailed host address:
\n";
print "$hostaddress

\n";
print "Display browser info:
\n";
print "$browser

\n";
print "Where you came from (if you clicked on a link to get here:
\n";
if ($referred == "") {
print "Page was directly requested";
}
else {
print "$referred";
}

No comments:

Post a Comment