Skip to content

Fix PHP version check for geoip2.phar compatibility#754

Merged
sstidl merged 2 commits intomasterfrom
copilot/fix-php-version-check-getip
Jan 31, 2026
Merged

Fix PHP version check for geoip2.phar compatibility#754
sstidl merged 2 commits intomasterfrom
copilot/fix-php-version-check-getip

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 31, 2026

User description

getIP.php checks PHP_MAJOR_VERSION >= 8 before loading geoip2.phar, but the phar requires PHP 8.1.0+ (PHP_VERSION_ID >= 80100). This causes HTTP 500 errors on PHP 8.0.x installations.

Changes

  • Line 137: Changed condition from PHP_MAJOR_VERSION >= 8 to PHP_VERSION_ID >= 80100
  • Line 141: Changed condition from PHP_MAJOR_VERSION < 8 to PHP_VERSION_ID < 80100
// Before
if (PHP_MAJOR_VERSION >= 8){
    require_once("geoip2.phar");
}
function getIspInfo_ipinfoOfflineDb($ip){
    if (PHP_MAJOR_VERSION < 8 || !file_exists(OFFLINE_IPINFO_DB_FILE) || !is_readable(OFFLINE_IPINFO_DB_FILE)){
        return null;
    }
    // ...
}

// After
if (PHP_VERSION_ID >= 80100){
    require_once("geoip2.phar");
}
function getIspInfo_ipinfoOfflineDb($ip){
    if (PHP_VERSION_ID < 80100 || !file_exists(OFFLINE_IPINFO_DB_FILE) || !is_readable(OFFLINE_IPINFO_DB_FILE)){
        return null;
    }
    // ...
}

This aligns with geoip2.phar's vendor/composer/platform_check.php which enforces PHP_VERSION_ID >= 80100.

Original prompt

This section details on the original issue you should resolve

<issue_title>Incorrect php version check in getIP.php</issue_title>
<issue_description>## Description
getIP.php only check PHP_MAJOR_VERSION >= 8 while loading geoip2.phar. But in geoip2.phar/vendor/composer/platform_check.php it checks PHP_VERSION_ID >= 80100, otherwise it will cause a fatal error. As getIP.php has set error_reporting(0), if the server use php v8.0.0 it will return HTTP 500 with nothing.

Server

nginx, php v8.0.0

Client

any

Steps to reproduce

visit /backend/getIP.php</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


PR Type

Bug fix


Description

  • Fix PHP version check for geoip2.phar compatibility

  • Changed from PHP_MAJOR_VERSION >= 8 to PHP_VERSION_ID >= 80100

  • Prevents HTTP 500 errors on PHP 8.0.x installations

  • Aligns with geoip2.phar's actual requirement of PHP 8.1.0+


Diagram Walkthrough

flowchart LR
  A["PHP Version Check"] -->|Before: PHP_MAJOR_VERSION >= 8| B["Fails on PHP 8.0.x"]
  A -->|After: PHP_VERSION_ID >= 80100| C["Works on PHP 8.1.0+"]
  B -->|Causes| D["HTTP 500 Error"]
  C -->|Prevents| D
Loading

File Walkthrough

Relevant files
Bug fix
getIP.php
Update PHP version checks for geoip2.phar                               

backend/getIP.php

  • Updated geoip2.phar loading condition from PHP_MAJOR_VERSION >= 8 to
    PHP_VERSION_ID >= 80100 (line 137)
  • Updated offline database check condition from PHP_MAJOR_VERSION < 8 to
    PHP_VERSION_ID < 80100 (line 141)
  • Ensures compatibility with geoip2.phar's actual PHP 8.1.0+ requirement
+2/-2     

Changed from PHP_MAJOR_VERSION >= 8 to PHP_VERSION_ID >= 80100 to match
the actual requirement of geoip2.phar which needs PHP 8.1.0 or higher.
This prevents HTTP 500 errors on PHP 8.0.x installations.

Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect PHP version check in getIP.php Fix PHP version check for geoip2.phar compatibility Jan 31, 2026
Copilot AI requested a review from sstidl January 31, 2026 20:43
@sstidl sstidl marked this pull request as ready for review January 31, 2026 20:45
@sstidl sstidl merged commit 734a35f into master Jan 31, 2026
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🟡
🎫 #753
🟢 Fix the PHP version check in getIP.php to properly validate PHP 8.1.0+ requirement instead
of just PHP 8+
Prevent HTTP 500 errors when running on PHP 8.0.x by ensuring geoip2.phar is only loaded
on compatible PHP versions
Align version check with geoip2.phar's actual requirement of PHP_VERSION_ID >= 80100
Handle the case where error_reporting(0) hides the fatal error from
geoip2.phar/vendor/composer/platform_check.php
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing error handling: The code loads geoip2.phar without error handling if the file is missing or incompatible,
which could cause fatal errors.

Referred Code
if (PHP_VERSION_ID >= 80100){
    require_once("geoip2.phar");
}

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@sstidl sstidl deleted the copilot/fix-php-version-check-getip branch March 11, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect php version check in getIP.php

2 participants