getClientIp() will now only return valid IP addresses, rather than assuming the X_FORWARDED_FOR is the first comma seperated value.
This commit is contained in:
parent
78747e6cc5
commit
7b5328f1c7
@ -546,9 +546,16 @@ class Request
|
|||||||
if ($this->server->has('HTTP_CLIENT_IP')) {
|
if ($this->server->has('HTTP_CLIENT_IP')) {
|
||||||
return $this->server->get('HTTP_CLIENT_IP');
|
return $this->server->get('HTTP_CLIENT_IP');
|
||||||
} elseif ($this->server->has('HTTP_X_FORWARDED_FOR')) {
|
} elseif ($this->server->has('HTTP_X_FORWARDED_FOR')) {
|
||||||
$clientIp = explode(',', $this->server->get('HTTP_X_FORWARDED_FOR'), 2);
|
$clientIp = explode(',', $this->server->get('HTTP_X_FORWARDED_FOR'));
|
||||||
|
|
||||||
return isset($clientIp[0]) ? trim($clientIp[0]) : '';
|
foreach ($clientIp as $ipAddress) {
|
||||||
|
$cleanIpAddress = trim($ipAddress);
|
||||||
|
|
||||||
|
if (false !== filter_var($cleanIpAddress, FILTER_VALIDATE_IP)) {
|
||||||
|
return $cleanIpAddress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user