Https protocol how to get client ip

I’ve this simple wrapper to get the client ip

class App_Server
    public static function getClientIp($checkProxy = true)
        if ($checkProxy && isset($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } else if ($checkProxy && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];

        return $ip;

but it doesn’t work with https protocol.

Is there a way to get the client ip for a site using https ?


Yeah I’m on a old zf version :slight_smile:

First thing I would recommend is to examining your $_SERVER array
while accessing your site with https
See what’s there, maybe it’s not called $_SERVER[‘REMOTE_ADDR’] and instead is called

The only way to find out is to pring_r($_SERVER) and see what you got in there

Yeah it’s the first thing I’ve done :slight_smile:
but I’ve always the same value in $_SERVER[‘REMOTE_ADDR’] :frowning:

So what exactly is not working then? If you have the REMOVE_ADDR value, then it’s working, right?

It’s always the same for all my users :frowning:
For instance in an other site my ip is (ie)
in the https site is (ie) and this is
the same for all my users

Who are all your users? Is it possible that they all access from your own company? This ip looks like reserved address and can only be used internally. Maybe you have some type of reverse proxy somewhere at your host or office?

Thanks for your time.
No, it’s a web site (sorry but I can’t post the url) and the users come from all over the world
even if mainly from Italy.