/** * 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; }
/** * UtilityTest::testGetClientIp() * * @covers ::getClientIp * @return void */ public function testGetClientIp() { $res = Utility::getClientIp(); $this->assertEquals(env('REMOTE_ADDR'), $res); }
/** * @covers ::getClientIp * @return void */ public function testGetClientIp() { $res = Utility::getClientIp(); $this->assertSame((string) env('REMOTE_ADDR'), $res); }