@@ -250,16 +250,16 @@ public static function ipGet($ip_type_to_get = 'real', $v4_only = true, $headers
250250 $ out = $ out ?: self ::ipGet ('clientside ' , $ v4_only , $ headers );
251251
252252 $ ip_version = self ::ipValidate ($ out );
253-
253+ $ platform_server_address = self :: getPlatformServerAddr ();
254254 // Is private network
255255 if (
256256 ! $ out ||
257257 (
258258 is_string ($ ip_version ) && (
259259 self ::ipIsPrivateNetwork ($ out , $ ip_version ) ||
260260 (
261- $ ip_version === self ::ipValidate ($ _SERVER [ ' SERVER_ADDR ' ] ) &&
262- self ::ipMaskMatch ($ out , $ _SERVER [ ' SERVER_ADDR ' ] . '/24 ' , $ ip_version )
261+ $ ip_version === self ::ipValidate ($ platform_server_address ) &&
262+ self ::ipMaskMatch ($ out , $ platform_server_address . '/24 ' , $ ip_version )
263263 )
264264 )
265265 )
@@ -547,4 +547,33 @@ public static function fromUTF8($obj, $data_codepage = null)
547547
548548 return $ obj ;
549549 }
550+
551+ /**
552+ * Get server IP address with cross-platform compatibility
553+ *
554+ * @return string|null
555+ */
556+ public static function getPlatformServerAddr ()
557+ {
558+ if ( isset ($ _SERVER ['SERVER_ADDR ' ]) && self ::ipValidate ($ _SERVER ['SERVER_ADDR ' ])) {
559+ // Any standard case
560+ return $ _SERVER ['SERVER_ADDR ' ];
561+ } elseif ( isset ($ _SERVER ['LOCAL_ADDR ' ]) && self ::ipValidate ($ _SERVER ['LOCAL_ADDR ' ])) {
562+ // Windows IIS
563+ return $ _SERVER ['LOCAL_ADDR ' ];
564+ }
565+ // Additional fallbacks for other platforms if needed
566+ if ( isset ($ _SERVER ['HTTP_HOST ' ]) ) {
567+ $ http_host = $ _SERVER ['HTTP_HOST ' ];
568+ // Remove port if present (e.g., "192.168.1.1:8080" -> "192.168.1.1")
569+ if (strpos ($ http_host , ': ' ) !== false ) {
570+ $ http_host = strstr ($ http_host , ': ' , true );
571+ }
572+ if ( self ::ipValidate ($ http_host ) ) {
573+ return $ http_host ;
574+ }
575+ }
576+
577+ return null ;
578+ }
550579}
0 commit comments