Skip to content

Commit c9fdd2f

Browse files
authored
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
1 parent 33390e9 commit c9fdd2f

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

backend/getIP.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function getIspInfo_ipinfoApi($ip){
138138
require_once("geoip2.phar");
139139
}
140140
function getIspInfo_ipinfoOfflineDb($ip){
141-
if (!file_exists(OFFLINE_IPINFO_DB_FILE) || !is_readable(OFFLINE_IPINFO_DB_FILE)){
141+
if (PHP_MAJOR_VERSION < 8 || !file_exists(OFFLINE_IPINFO_DB_FILE) || !is_readable(OFFLINE_IPINFO_DB_FILE)){
142142
return null;
143143
}
144144
$reader = new MaxMind\Db\Reader(OFFLINE_IPINFO_DB_FILE);
@@ -181,21 +181,16 @@ function formatResponse_simple($ip,$ispName=null){
181181
if (is_string($localIpInfo)) {
182182
echo formatResponse_simple($ip,$localIpInfo);
183183
}else{
184-
//ipinfo API and offline db require PHP 8 or newer
185-
if (PHP_MAJOR_VERSION >= 8){
186-
$r=getIspInfo_ipinfoApi($ip);
184+
$r=getIspInfo_ipinfoApi($ip);
185+
if(!is_null($r)){
186+
echo $r;
187+
}else{
188+
$r=getIspInfo_ipinfoOfflineDb($ip);
187189
if(!is_null($r)){
188190
echo $r;
189191
}else{
190-
$r=getIspInfo_ipinfoOfflineDb($ip);
191-
if(!is_null($r)){
192-
echo $r;
193-
}else{
194-
echo formatResponse_simple($ip);
195-
}
192+
echo formatResponse_simple($ip);
196193
}
197-
}else{
198-
echo formatResponse_simple($ip);
199194
}
200195
}
201196
}else{

0 commit comments

Comments
 (0)