Skip to content

Commit fb0066e

Browse files
committed
Fix for multiple proxies
1 parent 50f9c15 commit fb0066e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Deployer.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,22 @@ private function logPostedData()
242242

243243
protected function getIp()
244244
{
245+
$ip = null;
246+
245247
if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
246-
return $_SERVER['HTTP_CF_CONNECTING_IP'];
248+
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
247249
}
248250
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
249-
return $_SERVER['HTTP_X_FORWARDED_FOR'];
251+
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
250252
}
251253
if (!empty($_SERVER['REMOTE_ADDR'])) {
252-
return $_SERVER['REMOTE_ADDR'];
254+
$ip = $_SERVER['REMOTE_ADDR'];
253255
}
254-
return null;
256+
257+
// If there are multiple proxies, X_FORWARDED_FOR is a comma and space separated list of IPs
258+
$ip = explode(', ', $ip);
259+
260+
return $ip[0];
255261
}
256262

257263
/**

0 commit comments

Comments
 (0)