Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14318 reviews 1707 hosting providers

Questions & Answers

Getting real IP address in PHP

May 21, 2012 by mike231
I have a client who is connected to the Internet through Proxy Server and $_SERVER['REMOTE_ADDR'] in PHP just returns the the IP address of the proxy server not of the client’s machine. Does anyone know a function in PHP to find the real IP address of the client’s machine.
Appreciate your help

1 Answer

0 votes
May 21, 2012 by lionhost
Try this
function getRealIpAddr()
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from shared internet
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip  from proxy
    return $ip;