mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 22:02:15 +00:00
Add $safe
This commit is contained in:
@@ -158,22 +158,24 @@ class Request
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id address
|
* Get id address
|
||||||
|
* If $safe is false, this function will detect Proxys. But the user can edit this header to whatever he wants!
|
||||||
|
* https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php#comment-25086804
|
||||||
|
* @param bool $safe
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getIp(): ?string
|
public function getIp(bool $safe = false): ?string
|
||||||
{
|
{
|
||||||
if ($this->getHeader('http-cf-connecting-ip') !== null) {
|
if ($this->getHeader('http-cf-connecting-ip') !== null) {
|
||||||
return $this->getHeader('http-cf-connecting-ip');
|
return $this->getHeader('http-cf-connecting-ip');
|
||||||
}
|
}
|
||||||
|
if(!$safe){
|
||||||
if($this->getHeader('http-client-ip') !== null){
|
if($this->getHeader('http-client-ip') !== null){
|
||||||
return $this->getHeader('http-client-ip');
|
return $this->getHeader('http-client-ip');
|
||||||
|
}
|
||||||
|
if($this->getHeader('http-x-forwarded-for') !== null){
|
||||||
|
return $this->getHeader('http-x-forwarded-for');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getHeader('http-x-forwarded-for') !== null) {
|
|
||||||
return $this->getHeader('http-x-forwarded-for');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getHeader('remote-addr');
|
return $this->getHeader('remote-addr');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user