Problem to find the IP

Asked

Viewed 37 times

1

function getRealIP() {

    if (!empty($_SERVER['HTTP_CLIENT_IP']))
        return $_SERVER['HTTP_CLIENT_IP'];

    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
        return $_SERVER['HTTP_X_FORWARDED_FOR'];

    return $_SERVER['REMOTE_ADDR'];
}

echo getRealIP();

echo $_SERVER['REMOTE_ADDR'];

What’s wrong with that code? 'Cause that’s the only way his score works ::1, tried several times and only gives this result.

  • If you are running the local network script, the result will be this. This is the interface IP lo (loopback). Try using in production or on a test platform like phptester.net

1 answer

3

No error, it is returning the value of Ipv6:

"The localhost name usually resolves to Ipv4 loopback address 127.0.0.1 , and to Ipv6 return address :: 1."

Try to configure Apache correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.