Thursday, October 15, 2009

To get the real IP using PHP code

The code will get the real IP address of running those scripts.


<?php


function getRealIpAddress()

{

if (!empty($_SERVER['HTTP_CLIENT_IP']))


//check ip from share internet

{

$ip=$_SERVER['HTTP_CLIENT_IP'];

}

elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))


//to check ip is pass from proxy


{

$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];

}

else

{

$ip=$_SERVER['REMOTE_ADDR'];

}

return $ip;

}



echo getRealIpAddress(); // display the real IP address

?>


it will be useful.

1 comment: