Skip to content

Commit 2aed212

Browse files
committed
- Support double IP addresses #25
1 parent ed3965a commit 2aed212

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/GeoIP.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -229,26 +229,24 @@ public function getCache()
229229
*/
230230
public function getClientIP()
231231
{
232-
if ($ip = getenv('HTTP_CLIENT_IP')) {
233-
return $ip;
234-
}
235-
else if ($ip = getenv('HTTP_X_FORWARDED_FOR')) {
236-
return $ip;
237-
}
238-
else if ($ip = getenv('HTTP_X_FORWARDED')) {
239-
return $ip;
240-
}
241-
else if ($ip = getenv('HTTP_FORWARDED_FOR')) {
242-
return $ip;
243-
}
244-
else if ($ip = getenv('HTTP_FORWARDED')) {
245-
return $ip;
246-
}
247-
else if ($ip = getenv('REMOTE_ADDR')) {
248-
return $ip;
249-
}
250-
else if (isset($_SERVER['REMOTE_ADDR'])) {
251-
return $_SERVER['REMOTE_ADDR'];
232+
$remotes_keys = [
233+
'HTTP_X_FORWARDED_FOR',
234+
'HTTP_CLIENT_IP',
235+
'HTTP_X_FORWARDED',
236+
'HTTP_FORWARDED_FOR',
237+
'HTTP_FORWARDED',
238+
'REMOTE_ADDR',
239+
'HTTP_X_CLUSTER_CLIENT_IP',
240+
];
241+
242+
foreach ($remotes_keys as $key) {
243+
if ($address = getenv($key)) {
244+
foreach (explode(',', $address) as $ip) {
245+
if ($this->isValid($ip)) {
246+
return $ip;
247+
}
248+
}
249+
}
252250
}
253251

254252
return '127.0.0.0';

0 commit comments

Comments
 (0)