1.

How to get IP Address of clients machine?

Answer»

If we USED $_SERVER[‘REMOTE_ADDR’] to get an IP address, but sometimes it will not return the correct value. If the client is connected with the INTERNET through Proxy Server then $_SERVER[‘REMOTE_ADDR’] in PHP, it returns the IP address of the proxy server not of the user’s machine.

So here is a simple FUNCTION in PHP to FIND the real IP address of the user’s machine.

Example

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    ELSEIF (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}



Discussion

No Comment Found