X
X
xmoonlight2015-01-05 16:07:41
PHP
xmoonlight, 2015-01-05 16:07:41

Determination of the IP address. Which to choose?

Here is the situation:
$_SERVER['HTTP_X_FORWARDED_FOR']: 111.111.111.111
$_SERVER['REMOTE_ADDR']: 222.222.222.222
Which visitor's IP is considered correct?
What if there are more headlines?
Is there a single correct method for determining a user's IP?
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
X
xmoonlight, 2015-01-16
@xmoonlight

Just like this: $_SERVER['REMOTE_ADDR'];
because everything else is fake :(

S
Sergey Nalomenko, 2015-01-05
@nalomenko

This article will help you

M
Melkij, 2015-01-05
@melkij

What IP of the visitor is considered correct?

Both.
Log everything.
In general, write REMOTE_ADDR. Configure your web servers to issue REMOTE_ADDR to the address that opened the connection to the frontend.

V
Volodymyr Godyak, 2015-01-06
@wmgodyak

private function getUserIp(){
        if (!empty($_SERVER['HTTP_X_REAL_IP']))   //check ip from share internet
        {
            $ip=$_SERVER['HTTP_X_REAL_IP'];
        }
        elseif (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
        {
            $ip=$_SERVER['HTTP_CLIENT_IP'];
        }
        elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
        {
            $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        else
        {
            $ip=$_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question