Skip to content

Commit f2e0f47

Browse files
authored
Updated AbstractOAuth2Controller with X-Real-IP
Added additional PHP Server variable to check when attempting to determine the client's IP address.
1 parent 838090b commit f2e0f47

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/Controllers/AbstractOAuth2Controller.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public function __construct()
5050
'X-Longitude' => $_SERVER['GEOIP_LONGITUDE']
5151
];
5252
}
53-
$clientIpAddress = $this->getClientIP();
54-
$this->headers['X-Forwarded-For'] = $clientIpAddress;
53+
if (!is_null($clientIpAddress = $this->getClientIP())) {
54+
$this->headers['X-Forwarded-For'] = $clientIpAddress;
55+
}
5556
$this->encryption = DI::container()->get(EncryptionProvider::class);
5657
$this->secureStorage = DI::container()->get(SecureCookieProvider::class);
5758
$this->secureStorage->setEncryptionProvider($this->encryption);
@@ -109,20 +110,24 @@ public function setEncryptionProvider(EncryptionInterface $encryptionProvider):
109110
return $this;
110111
}
111112

112-
/**
113+
/**
113114
* looks for a user's IP address
114115
*
115-
* @return string
116+
* @return string|null
116117
*/
117-
public function getClientIP(){
118-
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)){
119-
return $_SERVER["HTTP_X_FORWARDED_FOR"];
120-
}else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
118+
public function getClientIP()
119+
{
120+
if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) {
121+
return $_SERVER["HTTP_X_REAL_IP"];
122+
} else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
123+
return $_SERVER["HTTP_X_FORWARDED_FOR"];
124+
} else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
121125
return $_SERVER["REMOTE_ADDR"];
122-
}else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
126+
} else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
123127
return $_SERVER["HTTP_CLIENT_IP"];
124-
}
125-
return '';
128+
}
129+
130+
return null;
126131
}
127132

128133
/**

0 commit comments

Comments
 (0)