'Strange behaviour in getting Real User IP [closed]

Maybe someone could help me understand, because I m facing something that seems strange for me... maybe for a lake of knowledge arround http requests.

Please consider, that this is not happening always.

So I have a friend that try to access my website using his smartphone within the 4g network. Lets says his IP once he reached the website apears to be : xxx.xxx.xx.xx

But then he switched connexion to access Internet using his house wifi, and reach my website again.

How it is possible that he reached my website 2 times with the same IP adress ?

He is not using proxies. Note that making a whois request on the IP adress, it appears that the ip is owned by his mobile network provider, that is different from his house network provider.

So I cannot explain how he could be connected to internet with his internet box at home, and navigating the web with an IP that seems to be owned by his mobile network provider

For information this is the PHP function I m using to check the client IP adress (found on stackoverflow) :

private function getUserIP(){
        if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
            $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
            $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
        }
        $client  = @$_SERVER['HTTP_CLIENT_IP'];
        $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
        $remote  = $_SERVER['REMOTE_ADDR'];

        if(filter_var($client, FILTER_VALIDATE_IP)){
            $ip = $client;
        }
        else if(filter_var($forward, FILTER_VALIDATE_IP)){
            $ip = $forward;
        }
        else{
            $ip = $remote;
        }
        return $ip;
    }

Thanks for the help !

Edit in order to give more details based on questions on comments :

How did you confirm that the IP belongs to the mobile provider?

I've done a whois check on the IP, and it appears to belong to a company that is his mobile nework provider. So I can't be sure at 100% but I m quiet confident that this is his mobile network IP.

Have you never heard of Mobile IP?

No ! But it's a very interesting comment, and for the moment is the best possible explanation of what it's happening. I m going to read a bit more about how this works, the strange point is why his mobile device doesn't act the same way when connected on his neighbor Wifi ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source