getClientIp() 공개 정적인 메소드

Get the current IP address.
public static getClientIp ( boolean $safe = true ) : string
$safe boolean
리턴 string IP address
예제 #1
0
 /**
  * Returns current IP address.
  * Note that in debug mode it will emulate it - and retrieve the preconfigured one.
  *
  * NEW: if many ips in row (ip1, ip2, ip3), use last (or first???) one!
  *
  * @return string IP
  */
 public static function findIp()
 {
     if ((int) Configure::read('debug') > 1) {
         if ($ip = Configure::read('App.defaultIp')) {
             return $ip;
         }
         return '127.0.0.1';
     }
     $ip = Utility::getClientIp();
     # usually getClientIp already removes multiple ips in favor of one single ip. but seems to fail sometimes
     if (strpos($ip, ',') !== false) {
         return false;
         //$ips = explode(',', $ip);
         //$ip = trim($ips[0]); # first
         //$ip = trim($ips[count($ips)-1]); # last
     }
     return $ip;
 }
예제 #2
0
 /**
  * UtilityTest::testGetClientIp()
  *
  * @covers ::getClientIp
  * @return void
  */
 public function testGetClientIp()
 {
     $res = Utility::getClientIp();
     $this->assertEquals(env('REMOTE_ADDR'), $res);
 }
예제 #3
0
 /**
  * @covers ::getClientIp
  * @return void
  */
 public function testGetClientIp()
 {
     $res = Utility::getClientIp();
     $this->assertSame((string) env('REMOTE_ADDR'), $res);
 }