2

I used

if(!empty($_SERVER['HTTP_CLIENT_IP']))
{
        //check ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
        //to check ip is pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
else{
        $ip = $_SERVER['REMOTE_ADDR'];
    }

echo  $ip;

to get client ip address

It is working when I test it on my local server but when I upload my files into remote server where i am hosting my web it is fetching my server ip address not client ip

Vaibhav Jain
  • 493
  • 2
  • 7
  • 13
  • Is it possible that the client you have tested with is on same machine where your server is? I am using exactly same function and it is giving correct results to me – Bhavik Shah Nov 11 '13 at 07:02
  • I think its already answered here http://stackoverflow.com/questions/3003145/how-to-get-client-ip-address-in-php and here http://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php?rq=1 – user2633780 Nov 11 '13 at 07:03

1 Answers1

1

Your server might be behind an internal proxy or a load balancer. Try using my PHP Utilities Functions library which has code for this.

dotancohen
  • 30,064
  • 36
  • 138
  • 197