@@ -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