Doubts with IP function

0

I use the following function below to search for the user's IP, regardless of the type of connection or device it uses.

  function get_client_ip() {
$ipaddress = '';
if ( isset( $_SERVER[ 'HTTP_CLIENT_IP' ] ) )
    $ipaddress = $_SERVER[ 'HTTP_CLIENT_IP' ];
else if ( isset( $_SERVER[ 'HTTP_X_FORWARDED_FOR' ] ) )
    $ipaddress = $_SERVER[ 'HTTP_X_FORWARDED_FOR' ];
else if ( isset( $_SERVER[ 'HTTP_X_FORWARDED' ] ) )
    $ipaddress = $_SERVER[ 'HTTP_X_FORWARDED' ];
else if ( isset( $_SERVER[ 'HTTP_FORWARDED_FOR' ] ) )
    $ipaddress = $_SERVER[ 'HTTP_FORWARDED_FOR' ];
else if ( isset( $_SERVER[ 'HTTP_FORWARDED' ] ) )
    $ipaddress = $_SERVER[ 'HTTP_FORWARDED' ];
else if ( isset( $_SERVER[ 'REMOTE_ADDR' ] ) )
    $ipaddress = $_SERVER[ 'REMOTE_ADDR' ];
else
    $ipaddress = 'UNKNOWN';

return $ipaddress;
 }

It works perfectly. It registers the user's IP in a mysql table.

I decided to do a test, echoing the PHP page, as shown below, then it will display the user's IP.

 echo get_client_ip();

When I use a device with wi-fi access, it normally displays IP. The problem is that when you access this same PHP page through a mobile phone using 'mobile data', instead of displaying the IP of the same, it displays other information, as shown below and not your real IP:

 2804:d45:b18:94bc::1

The curious thing is that it saves the IP normally (and not this information as shown above), only when I ask to give the echo above, it displays this way. Could you explain why?

    
asked by anonymous 16.05.2018 / 13:52

0 answers