Answer the question
In order to leave comments, you need to log in
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
Just like this: $_SERVER['REMOTE_ADDR'];
because everything else is fake :(
What IP of the visitor is considered correct?
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 questionAsk a Question
731 491 924 answers to any question