Zend Framework

Add a method to retrieve the remote IP

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.9.0
  • Component/s: Zend_Controller
  • Labels:
    None

Description

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

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;
}

Activity

Hide
Matthew Weier O'Phinney added a comment -

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

Show
Matthew Weier O'Phinney added a comment - Assigning back to Jurrien, as he knows the implementation desired. Please don't forget to write tests for the functionality.
Hide
Jurrien Stutterheim added a comment -

Resolved in r16267. Merged to release-1.8 in r16268

Show
Jurrien Stutterheim added a comment - Resolved in r16267. Merged to release-1.8 in r16268
Hide
Kazusuke Sasezaki added a comment -

Is not under "IP address spoofing"?

please check.Similar issue - cakephp's https://trac.cakephp.org/ticket/5842

Show
Kazusuke Sasezaki added a comment - Is not under "IP address spoofing"? please check.Similar issue - cakephp's https://trac.cakephp.org/ticket/5842
Hide
Jurrien Stutterheim added a comment -
Show
Jurrien Stutterheim added a comment - Opened a new issue for that: http://framework.zend.com/issues/browse/ZF-7117

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: