getIpAddress() public method

Returns the IP address of the client using the given methods.
public getIpAddress ( mixed $source = null ) : string
$source mixed (optional) The source data. If omitted, the class will use the value passed to Whip::setSource or fallback to $_SERVER.
return string Returns the IP address as a string or false if no IP address could be found.
示例#1
0
 public function onResult(MvcEvent $event)
 {
     parent::onResult($event);
     if ($event->isError()) {
         if ($this->logger) {
             $this->logger->info(sprintf('Unauthorized ip address "%s" attempted to push Recurly notification.', $this->whip->getIpAddress()));
         }
         $event->getResponse()->setStatusCode(HttpResponse::STATUS_CODE_403);
     }
 }
示例#2
0
 /**
  * Test HTTP_X_REAL_IP header.
  */
 public function testHttpXRealIpHeader()
 {
     $_SERVER = array('REMOTE_ADDR' => '127.0.0.1', 'HTTP_X_REAL_IP' => '24.24.24.24');
     $lookup = new Whip(Whip::PROXY_HEADERS | Whip::REMOTE_ADDR);
     $this->assertEquals('24.24.24.24', $lookup->getIpAddress());
 }
示例#3
0
 /**
  * Tests that if we specify the source array through Whip::setSource, the
  * class will override any values found in $_SERVER.
  */
 public function testSetSourceArrayOverridesServerSuperglobal()
 {
     $source = array('REMOTE_ADDR' => '24.24.24.24');
     $lookup = new Whip(Whip::REMOTE_ADDR, array(), array('REMOTE_ADDR' => '127.0.0.1'));
     $this->assertNotEquals($source['REMOTE_ADDR'], $lookup->getIpAddress());
     $lookup->setSource($source);
     $this->assertEquals($source['REMOTE_ADDR'], $lookup->getIpAddress());
 }