public static function ip() { $ip = Arrays::getValue($_SERVER, 'HTTP_CLIENT_IP'); if (!$ip) { $ip = Arrays::getValue($_SERVER, 'HTTP_X_FORWARDED_FOR'); } if (!$ip) { $ip = Arrays::getValue($_SERVER, 'REMOTE_ADDR'); } return $ip; }
/** * @test */ public function shouldReturnIpFromREMOTE_ADDR() { //given $_SERVER['REMOTE_ADDR'] = '10.170.12.53'; //when $ip = RequestHeaders::ip(); //then $this->assertEquals('10.170.12.53', $ip); }