Ticket #2798: x_forwarded_for.patch
| File x_forwarded_for.patch, 2.7 kB (added by Nebelmann, 1 year ago) |
|---|
-
test/unit/request/sfWebRequestTest.php
old new 137 137 $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; 138 138 $t->is($request->getRemoteAddress(), '127.0.0.1', '->getRemoteAddress() returns the remote address'); 139 139 140 // ->getForwarded RemoteAddress()141 $t->diag('->getForwarded RemoteAddress()');142 $t->is($request->getForwarded RemoteAddress(), null, '->getForwardedRemoteAddress() returns null if the request was not forwarded.');143 $_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1 ';144 $t->is ($request->getForwardedRemoteAddress(), '10.0.0.1', '->getForwardedRemoteAddress() returns the value from HTTP_X_FORWARDED_FOR');140 // ->getForwardedFor() 141 $t->diag('->getForwardedFor()'); 142 $t->is($request->getForwardedFor(), null, '->getForwardedFor() returns null if the request was not forwarded.'); 143 $_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.2'; 144 $t->is_deeply($request->getForwardedFor(), array('10.0.0.1', '10.0.0.2'), '->getForwardedFor() returns the value from HTTP_X_FORWARDED_FOR'); 145 145 146 146 // methods 147 147 $t->diag('methods'); -
lib/request/sfWebRequest.class.php
old new 766 766 } 767 767 768 768 /** 769 * Returns the remote IP address forthe request.769 * Returns the remote IP address that made the request. 770 770 * 771 771 * @return string The remote IP address 772 772 */ … … 778 778 } 779 779 780 780 /** 781 * Returns the remote IP addressed after resolved from the forward. 781 * Returns an array containing a list of IPs, the first being the client address 782 * and the others the addresses of each proxy that passed the request. The address 783 * for the last proxy can be retrieved via getRemoteAddress(). 782 784 * 783 * This is useful if you are testing to see if the user is behind a proxy. However,784 * it should not be trusted.785 * This method returns null if no proxy passed this request. Note that some proxies 786 * do not use this header, and act as if they were the client. 785 787 * 786 * @return string|null The remote IP address resolved from a forward, null if none set 788 * @return string|null An array of IP from the client and the proxies that passed 789 * the request, or null if no proxy was used. 787 790 */ 788 public function getForwarded RemoteAddress()791 public function getForwardedFor() 789 792 { 790 793 $pathInfo = $this->getPathInfoArray(); 791 794 … … 794 797 return null; 795 798 } 796 799 797 return $pathInfo['HTTP_X_FORWARDED_FOR'];800 return split(', ', $pathInfo['HTTP_X_FORWARDED_FOR']); 798 801 } 799 802 800 803 /**

