Skip to content

Commit

Permalink
Update getIP.php return the ability to do online check for IP locatio…
Browse files Browse the repository at this point in the history
…n on older PHP version (#651)

This patch is returns the ability to do online check for IP location on older PHP version
  • Loading branch information
IRainman authored Aug 16, 2024
1 parent 33390e9 commit c9fdd2f
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions backend/getIP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit c9fdd2f

Please sign in to comment.