Return to Snippet

Revision: 66572
at May 27, 2014 21:00 by KhanOf21Century


Initial Code
<?php
if (!empty($_SERVER["HTTP_CLIENT_IP"]))
{
 //check for ip from share internet
 $ip = $_SERVER["HTTP_CLIENT_IP"];
}
elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
{
 // Check for the Proxy User
 $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
else
{
 $ip = $_SERVER["REMOTE_ADDR"];
}

// This will print user's real IP Address
// does't matter if user using proxy or not.
echo $ip;

?>

Initial URL
http://topgravity.com/find-my-ip-address/

Initial Description
Code is meant to show the real ip address, in case if  user is using a proxy. Most of the time $_SERVER["REMOTE_ADDR"] do not work correctly due to the proxy setting of user. It's a nice solution.

Initial Title
Find a Real IP address when Proxy is used

Initial Tags
php, ip

Initial Language
PHP