PHP: Get IP/Host and Proxy Information

April 12th, 2008 · 4 Comments

Below is a method I use to detect the IP Address and Host Name as well as Proxy Information of a visitors.

if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"] != ""){

     // for proxy

     $IP = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];

     $proxy = $HTTP_SERVER_VARS["REMOTE_ADDR"];

     $host = @gethostbyaddr($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]);

}else{

     // for normal user

     $IP = $HTTP_SERVER_VARS["REMOTE_ADDR"];

     $host = @gethostbyaddr($HTTP_SERVER_VARS["REMOTE_ADDR"]);

}

[Read more →]

Tags: PHP