Skip to content

Commit

Permalink
Implemented fallback in getIP for PHP<8 (returns only the IP)
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfintel committed Aug 1, 2024
1 parent 52044aa commit 3d4f118
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
24 changes: 15 additions & 9 deletions backend/getIP.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ function getIspInfo_ipinfoApi($ip){
]);
}

require_once("geoip2.phar");
use MaxMind\Db\Reader;
if (PHP_MAJOR_VERSION >= 8){
require_once("geoip2.phar");
}
function getIspInfo_ipinfoOfflineDb($ip){
if (!file_exists(OFFLINE_IPINFO_DB_FILE) || !is_readable(OFFLINE_IPINFO_DB_FILE)){
return null;
}
$reader = new Reader(OFFLINE_IPINFO_DB_FILE);
$reader = new MaxMind\Db\Reader(OFFLINE_IPINFO_DB_FILE);
$data = $reader->get($ip);
if(!is_array($data)){
return null;
Expand Down Expand Up @@ -180,16 +181,21 @@ function formatResponse_simple($ip,$ispName=null){
if (is_string($localIpInfo)) {
echo formatResponse_simple($ip,$localIpInfo);
}else{
$r=getIspInfo_ipinfoApi($ip);
if(!is_null($r)){
echo $r;
}else{
$r=getIspInfo_ipinfoOfflineDb($ip);
//ipinfo API and offline db require PHP 8 or newer
if (PHP_MAJOR_VERSION >= 8){
$r=getIspInfo_ipinfoApi($ip);
if(!is_null($r)){
echo $r;
}else{
echo formatResponse_simple($ip);
$r=getIspInfo_ipinfoOfflineDb($ip);
if(!is_null($r)){
echo $r;
}else{
echo formatResponse_simple($ip);
}
}
}else{
echo formatResponse_simple($ip);
}
}
}else{
Expand Down
6 changes: 3 additions & 3 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ More guides will be added later
Server side, you'll need:

* Apache 2 (nginx and IIS also supported). A fast internet connection is required (possibly gigabit), and the web server must accept large POST requests (up to 20MB)
* PHP 5.4 or newer, a 64-bit version is strongly recommended
* PHP 5.4 or newer (8.0 required for ISP and distance detection), a 64-bit version is strongly recommended
* OpenSSL and its PHP module (this is usually installed automatically by most distros)
* If you want to store test results (telemetry), one of the following:
* MySQL/MariaDB and its PHP PDO module
Expand Down Expand Up @@ -153,7 +153,7 @@ This is the server that your users will first connect to. It hosts the UI, the J
Requirements:

* Apache 2 (nginx and IIS also supported). A fast connection is not mandatory, but is still recommended
* PHP 5.4 or newer
* PHP 5.4 or newer, a 64-bit version is strongly recommended
* If you want to store test results (telemetry), one of the following:
* MySQL/MariaDB and its PHP PDO module
* PostgreSQL and its PHP PDO module
Expand Down Expand Up @@ -241,7 +241,7 @@ These are the servers that will actually be used to perform the test.
Requirements:

* Apache 2 (nginx and IIS also supported). A fast internet connection is required (possibly gigabit), and the web server must accept large POST requests (up to 20MB)
* PHP 5.4 or newer
* PHP 5.4 or newer (8.0 required for ISP and distance detection)
* OpenSSL and its PHP module (this is usually installed automatically by most distros)

To install a backend, simply copy all the files in the `backend` folder to your backend server.
Expand Down

0 comments on commit 3d4f118

Please sign in to comment.