Thursday, August 9, 2007

PHP - get client ip address

Function can get client ip address using this function :)


function getIP() {
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
$ip = "UNKNOWN";
return $ip;




echo "Your IP :".$client_ip;



Anonymous said...

Thanks very useful website.. im expecting more..!

iamRandy said...

Thanks! This was exactly what I needed! Well done.

ilove said...

i try this scrip on my server. it not work in web proxy

this web proxy

Can i block IP client come from web proxy ?

i can't block IP from every web proxy.

sorry for my bad English.

Anonymous said...

the below code will work well and fine..

echo "
Your ip : " .GetHostByName($ip);

thank u...