0

How to get ip address of client.

I have checked through proxy REMOTE_ADDR,HTTP_X_FORWARDED_FOR but both not giving me correct ip

REMOTE_ADDR_IP is not working.

  • What do you mean by correct IP, then ? – BlitZ Feb 14 '14 at 08:22
  • possible duplicate of [How to get Client IP address in PHP?](http://stackoverflow.com/questions/3003145/how-to-get-client-ip-address-in-php) – Shankar Narayana Damodaran Feb 14 '14 at 08:22
  • possible duplicate of [How can I get the client's IP address in a PHP webservice?](http://stackoverflow.com/questions/1437771/how-can-i-get-the-clients-ip-address-in-a-php-webservice) – Rikesh Feb 14 '14 at 08:22

1 Answers1

1

I use the most reliable function I've found long ago

function getRealIpAddr() {
    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;
}
heximal
  • 10,327
  • 5
  • 46
  • 69
  • HTTP_X_FORWARDED_FOR is giving my own ip on proxy and REMOTE_ADDR is giving proxy's ip, Sometimes it interchanging. How this can be solved? – Shambhulal Verma Feb 14 '14 at 08:30