0

I have a subscription to a pro offer at OVH. I think that the php environment isn't well configured because when I try to request the client IP with the environment it returns a private IP such as 10.X.X.X wich changes every refreshing.

I tried to print the entire environment to see if the public IP is stored anywhere else, but it is not.

Have you got any ideas where it might comes from ?

Thanks.

Lucien Perouze
  • 590
  • 1
  • 4
  • 13
  • [How do I get the external IP of my server using PHP?](http://stackoverflow.com/questions/7909362/how-do-i-get-the-external-ip-of-my-server-using-php) – Sen Jacob Dec 13 '16 at 14:09
  • [How to identify server IP address in PHP](http://stackoverflow.com/questions/5800927/how-to-identify-server-ip-address-in-php) – Sen Jacob Dec 13 '16 at 14:10
  • [Retrieve external IP in PHP behind Haproxy](http://serverfault.com/questions/595270/retrieve-external-ip-in-php-behind-haproxy) – Sen Jacob Dec 13 '16 at 14:13

1 Answers1

0

seems like you are testing from your localhost. On your live server, the ip address should be properly displayed. Here is a simple function to further assist you:

function getUserIpAddress() {
        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;
    }
Rotimi
  • 4,783
  • 4
  • 18
  • 27