diff options
Diffstat (limited to 'application/HttpUtils.php')
-rw-r--r-- | application/HttpUtils.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/application/HttpUtils.php b/application/HttpUtils.php index 2e0792f9..354d261c 100644 --- a/application/HttpUtils.php +++ b/application/HttpUtils.php | |||
@@ -215,3 +215,29 @@ function page_url($server) | |||
215 | } | 215 | } |
216 | return index_url($server); | 216 | return index_url($server); |
217 | } | 217 | } |
218 | |||
219 | /** | ||
220 | * Retrieve the initial IP forwarded by the reverse proxy. | ||
221 | * | ||
222 | * Inspired from: https://github.com/zendframework/zend-http/blob/master/src/PhpEnvironment/RemoteAddress.php | ||
223 | * | ||
224 | * @param array $server $_SERVER array which contains HTTP headers. | ||
225 | * @param array $trustedIps List of trusted IP from the configuration. | ||
226 | * | ||
227 | * @return string|bool The forwarded IP, or false if none could be extracted. | ||
228 | */ | ||
229 | function getIpAddressFromProxy($server, $trustedIps) | ||
230 | { | ||
231 | $forwardedIpHeader = 'HTTP_X_FORWARDED_FOR'; | ||
232 | if (empty($server[$forwardedIpHeader])) { | ||
233 | return false; | ||
234 | } | ||
235 | |||
236 | $ips = preg_split('/\s*,\s*/', $server[$forwardedIpHeader]); | ||
237 | $ips = array_diff($ips, $trustedIps); | ||
238 | if (empty($ips)) { | ||
239 | return false; | ||
240 | } | ||
241 | |||
242 | return array_pop($ips); | ||
243 | } | ||