Created
April 7, 2015 16:29
-
-
Save agopaul/97b5dd6f3fc056d0812b to your computer and use it in GitHub Desktop.
Request IP util class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Utils; | |
| /** | |
| * Date: 04/04/2015 | |
| * @author Paolo Agostinetto <[email protected]> | |
| */ | |
| class RequestIp { | |
| /** | |
| * @var string | |
| */ | |
| protected $ip; | |
| /** | |
| * @var bool | |
| */ | |
| protected $isProxed = false; | |
| /** | |
| * @var string | |
| */ | |
| protected $proxyIp; | |
| /** | |
| * @var bool | |
| */ | |
| protected $isClodFlare = false; | |
| /** | |
| * @return Digitnut_Tools_RequestIp | |
| * @author Paolo Agostinetto <[email protected]> | |
| */ | |
| public static function factoryFromGlobals(){ | |
| $obj = new self(); | |
| if(isset($_SERVER['HTTP_USER_AGENT'])){ | |
| $obj->ip = $_SERVER['HTTP_X_REAL_IP']; | |
| $obj->proxyIp = $_SERVER['REMOTE_ADDR']; | |
| $obj->isProxed = true; | |
| } | |
| elseif(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){ | |
| $obj->ip = $_SERVER['HTTP_CF_CONNECTING_IP']; | |
| $obj->proxyIp = $_SERVER['REMOTE_ADDR']; | |
| $obj->isProxed = true; | |
| $obj->isClodFlare = true; | |
| } | |
| else{ | |
| $obj->ip = $_SERVER['REMOTE_ADDR']; | |
| } | |
| return $obj; | |
| } | |
| /** | |
| * @return string | |
| */ | |
| public function getIp() { | |
| return $this->ip; | |
| } | |
| /** | |
| * @return boolean | |
| */ | |
| public function isIsProxed() { | |
| return $this->isProxed; | |
| } | |
| /** | |
| * @return string | |
| */ | |
| public function getProxyIp() { | |
| return $this->proxyIp; | |
| } | |
| /** | |
| * @return boolean | |
| */ | |
| public function isIsClodFlare() { | |
| return $this->isClodFlare; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment