Recent Comments

Thursday, October 16, 2008

If you want to get your web site visitor's IP address then PHP provides you complete solution for this. I made a function to get IP address of visitor.

function visitorip() {
if (getenv('HTTP_CLIENT_IP')) $ip = getenv('HTTP_CLIENT_IP');
elseif (getenv('HTTP_X_FORWARDED_FOR')) $ip = getenv('HTTP_X_FORWARDED_FOR');
elseif (getenv('HTTP_X_FORWARDED')) $ip = getenv('HTTP_X_FORWARDED');
elseif (getenv('HTTP_FORWARDED_FOR')) $ip = getenv('HTTP_FORWARDED_FOR');
elseif (getenv('HTTP_FORWARDED')) $ip = getenv('HTTP_FORWARDED');
else $ip = $_SERVER['REMOTE_ADDR'];
return $ip;
}

echo "Your IP address is ".visitorip();
?>
In result web site visitor's ip address will appear. In example above i made a function named visitorip() will check all conditions for getting ip and will return ip address. echo command of PHP will receive ip address will display on page.

0 comments: