lionsoul2014/ip2region · error · Exception
invalid ip version number `{$header['ipVersion']}`
Error message
invalid ip version number `{$header['ipVersion']}` What it means
PHP versionFromHeader: the structure version is 3.0 but the header's ipVersion field matches neither the IPv4 nor IPv6 number, so the database's address family cannot be resolved; the header is invalid or from an unsupported generator.
Source
Thrown at binding/php/xdb/Searcher.class.php:98
// version parse from header
public static function versionFromHeader($header) {
// Old structure 2.0 with IPv4 supports ONLY
if ($header['version'] == Structure_20) {
return IPv4::default();
}
// structure 3.0 after IPv6 supporting
if ($header['version'] != Structure_30) {
throw new Exception("invalid xdb structure version `{$header['version']}`");
}
if ($header['ipVersion'] == IPv4VersionNo) {
return IPv4::default();
} else if ($header['ipVersion'] == IPv6VersionNo) {
return IPv6::default();
} else {
throw new Exception("invalid ip version number `{$header['ipVersion']}`");
}
}
// binary string chars implode with space
public static function bytesToString($buff, $offset, $length) {
$sb = [];
for ($i = 0; $i < $length; $i++) {
$sb[] = ord($buff[$offset+$i]) & 0xFF;
}
return '['.implode(' ', $sb).']';
}
// decode a 4bytes long with Little endian byte order from a byte buffer
public static function le_getUint32($b, $idx) {
$val = (ord($b[$idx])) | (ord($b[$idx+1]) << 8)
| (ord($b[$idx+2]) << 16) | (ord($b[$idx+3]) << 24);
// convert signed int to unsigned int if on 32 bit operating systemView on GitHub (pinned to c1a1fc7d59)
Solutions
- Use an xdb generated by a compatible maker that writes a correct ipVersion header
- Re-download the database to rule out corruption
- Report files with unknown ipVersion values to the maintainers and regenerate
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at binding/php/xdb/Searcher.class.php:98 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02).
Data as JSON: /api/errors/af009c45726d5e1b.
Report an issue: GitHub.