Changeset 10060
- Timestamp:
- 07/02/08 09:43:58 (5 months ago)
- Files:
-
- branches/1.2/lib/request/sfWebRequest.class.php (modified) (1 diff)
- branches/1.2/test/unit/request/sfWebRequestTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/request/sfWebRequest.class.php
r9960 r10060 1067 1067 1068 1068 /** 1069 * Returns the remote IP address for the request. 1070 * 1071 * @return string The remote IP address 1072 */ 1073 public function getRemoteAddress() 1074 { 1075 $pathInfo = $this->getPathInfoArray(); 1076 1077 return $pathInfo['REMOTE_ADDR']; 1078 } 1079 1080 /** 1081 * Returns the remote IP addressed after resolved from the forward. 1082 * 1083 * This is useful if you are testing to see if the user is behind a proxy. However, 1084 * it should not be trusted. 1085 * 1086 * @return string|null The remote IP address resolved from a forward, null if none set 1087 */ 1088 public function getForwardedRemoteAddress() 1089 { 1090 $pathInfo = $this->getPathInfoArray(); 1091 1092 if (empty($pathInfo['HTTP_X_FORWARDED_FOR'])) 1093 { 1094 return null; 1095 } 1096 1097 return $pathInfo['HTTP_X_FORWARDED_FOR']; 1098 } 1099 1100 /** 1069 1101 * Parses the request parameters. 1070 1102 * branches/1.2/test/unit/request/sfWebRequestTest.php
r9833 r10060 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(3 1, new lime_output_color());13 $t = new lime_test(34, new lime_output_color()); 14 14 15 15 class myRequest extends sfWebRequest … … 132 132 $_SERVER['HTTP_HOST'] = 'symfony-project.org:8043'; 133 133 $t->is($request->getUriPrefix(), 'https://symfony-project.org:8043', '->getUriPrefix() works for nonstandard https ports'); 134 135 // ->getRemoteAddress() 136 $t->diag('->getRemoteAddress()'); 137 $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; 138 $t->is($request->getRemoteAddress(), '127.0.0.1', '->getRemoteAddress() returns the remote address'); 139 140 // ->getForwardedRemoteAddress() 141 $t->diag('->getForwardedRemoteAddress()'); 142 $t->is($request->getForwardedRemoteAddress(), 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');