function getIpAddress()
{
if (trim($_SERVER['HTTP_CLIENT_IP'])!="") //checking ip address from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
else if (trim($_SERVER['HTTP_X_FORWARDED_FOR'])!="") //checking whether ip address is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
$ip_address = getIpAddress(); // Get the visitor's IP Address
echo $ip_address;
The above code snippet first tries to get the direct IP address of visitor’s machine, if not available then try for forwarded for IP address using HTTP_X_FORWARDED_FOR. And if this is not available too then it will finally get the IP address using REMOTE_ADDR. So that's it.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment