Wednesday, July 23, 2008

How to resolve visitor's IP address using PHP?

Recently working on some PHP programming to resolve the visitor's IP address when visiting to my PHP page :

<html>
<head>
<title>What is my IP address</title> </head>
<body>
<?
    if (getenv(HTTP_X_FORWARDED_FOR)) {
        $pipaddress = getenv(HTTP_X_FORWARDED_FOR);
        $ipaddress = getenv(REMOTE_ADDR);
echo "Your Proxy IP address is : ".$pipaddress. " (via $ipaddress) " ;
    } else {
        $ipaddress = getenv(REMOTE_ADDR);
        echo "Your IP address is : $ipaddress";
    }
?>
</body>
</html>

No comments: