Search code examples
phpzend-frameworkzend-http-client

Remote Address Parameter in Zend_Http_Client


Am developing a public site that uses the Zend_Http_Client to access remote logic.Is there a property/way in the Client adapter that I could set the remote address of the user browsing the site?

Currently am using this workaround which combines both remote address and remote useragent.

$client = new Zend_Http_Client();       
$client->setConfig(array(                       
    'useragent' => 'Get Remote Address'.'Get User Agent',       
)); 

Is there a specific property for remote address?


Solution

  • From any Zend_Controller_Action method you can retrieve the user's remote address as follows:

    $ip = $this->getRequest()->getServer('REMOTE_ADDR');
    

    If you're not in a Controller, you can use the following assuming the Front Controller was used:

    $ip = Zend_Controller_Front::getInstance()->getRequest()->getServer('REMOTE_ADDR');
    

    And finally - these methods are just wrappers for the SERVER superglobal:

    $ip = $_SERVER['REMOTE_ADDR'];
    

    Substitute REMOTE_ADDR with HTTP_USER_AGENT to get the user agent.