mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 21:12:14 +00:00
Validate IP header
This commit is contained in:
@@ -165,17 +165,18 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function getIp(bool $safe = false): ?string
|
public function getIp(bool $safe = false): ?string
|
||||||
{
|
{
|
||||||
|
$client_header = null;
|
||||||
if(!$safe){
|
if(!$safe){
|
||||||
if ($this->getHeader('http-cf-connecting-ip') !== null) {
|
if ($this->getHeader('http-cf-connecting-ip') !== null) {
|
||||||
return $this->getHeader('http-cf-connecting-ip');
|
$client_header = $this->getHeader('http-cf-connecting-ip');
|
||||||
}
|
}else if($this->getHeader('http-client-ip') !== null){
|
||||||
if($this->getHeader('http-client-ip') !== null){
|
$client_header = $this->getHeader('http-client-ip');
|
||||||
return $this->getHeader('http-client-ip');
|
}else if($this->getHeader('http-x-forwarded-for') !== null){
|
||||||
}
|
$client_header = $this->getHeader('http-x-forwarded-for');
|
||||||
if($this->getHeader('http-x-forwarded-for') !== null){
|
|
||||||
return $this->getHeader('http-x-forwarded-for');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if($client_header !== null && filter_var($client_header, FILTER_VALIDATE_IP))
|
||||||
|
return $client_header;
|
||||||
return $this->getHeader('remote-addr');
|
return $this->getHeader('remote-addr');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user