Clive Walkden

PHP, MySQL, HTML5, CSS3, jQuery code and ideas.

PHP Posts

PHP Function IP if behind a proxy

PHP Function IP if behind a proxy

in PHP
by
with 0 Comments

 

Following from my last post, here is the method to get your IP address if you are behind a proxy.
 
[code lang="php"]
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;
}
[/code]
 
As this method gets more accurate results it is better to use this than the previous function.
comments powered by Disqus