ZF-7092: Add a method to retrieve the remote IP

Issue Type: Improvement Created: 2009-06-22T19:45:43.000+0000 Last Updated: 2009-07-31T21:00:34.000+0000 Status: Resolved Fix version(s): - 1.9.0 (31/Jul/09)

Reporter: Jurrien Stutterheim (norm2782) Assignee: Jurrien Stutterheim (norm2782) Tags: - Zend_Controller

Related issues: Attachments:


Having a method in the HTTP request object to get the client's IP would be really useful. Proposed method:

<pre class="highlight">
public function getClientIp()
    if (!empty($this->getServer('HTTP_CLIENT_IP'))) {
        $ip = $this->getServer('HTTP_CLIENT_IP');
    } else if (!empty($this->getServer('HTTP_X_FORWARDED_FOR'))) {
        $ip = $this->getServer('HTTP_X_FORWARDED_FOR');
    } else {
        $ip = $this->getServer('REMOTE_ADDR');

    return $ip;


Posted by Matthew Weier O'Phinney (matthew) on 2009-06-23T04:41:13.000+0000

Assigning back to Jurrien, as he knows the implementation desired. :) Please don't forget to write tests for the functionality. :)

Posted by Jurrien Stutterheim (norm2782) on 2009-06-23T20:42:02.000+0000

Resolved in r16267. Merged to release-1.8 in r16268

Posted by Kazusuke Sasezaki (sasezaki) on 2009-06-24T08:52:27.000+0000

Is not under "IP address spoofing"?

please check.Similar issue - cakephp's

Posted by Jurrien Stutterheim (norm2782) on 2009-06-24T14:18:09.000+0000

Opened a new issue for that:

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.