From c9fdd2f693adf7e542e9e2e74021ef679ee0cab0 Mon Sep 17 00:00:00 2001 From: HedgehogInTheCPP Date: Fri, 16 Aug 2024 14:45:28 +0300 Subject: [PATCH] Update getIP.php return the ability to do online check for IP location on older PHP version (#651) This patch is returns the ability to do online check for IP location on older PHP version --- backend/getIP.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/backend/getIP.php b/backend/getIP.php index 675224acf..d7bc4fa81 100755 --- a/backend/getIP.php +++ b/backend/getIP.php @@ -138,7 +138,7 @@ function getIspInfo_ipinfoApi($ip){ require_once("geoip2.phar"); } function getIspInfo_ipinfoOfflineDb($ip){ - if (!file_exists(OFFLINE_IPINFO_DB_FILE) || !is_readable(OFFLINE_IPINFO_DB_FILE)){ + if (PHP_MAJOR_VERSION < 8 || !file_exists(OFFLINE_IPINFO_DB_FILE) || !is_readable(OFFLINE_IPINFO_DB_FILE)){ return null; } $reader = new MaxMind\Db\Reader(OFFLINE_IPINFO_DB_FILE); @@ -181,21 +181,16 @@ function formatResponse_simple($ip,$ispName=null){ if (is_string($localIpInfo)) { echo formatResponse_simple($ip,$localIpInfo); }else{ - //ipinfo API and offline db require PHP 8 or newer - if (PHP_MAJOR_VERSION >= 8){ - $r=getIspInfo_ipinfoApi($ip); + $r=getIspInfo_ipinfoApi($ip); + if(!is_null($r)){ + echo $r; + }else{ + $r=getIspInfo_ipinfoOfflineDb($ip); if(!is_null($r)){ echo $r; }else{ - $r=getIspInfo_ipinfoOfflineDb($ip); - if(!is_null($r)){ - echo $r; - }else{ - echo formatResponse_simple($ip); - } + echo formatResponse_simple($ip); } - }else{ - echo formatResponse_simple($ip); } } }else{