A maintained fork of the classic SypexGeo PHP reader, updated to work with PHP 8.x. It provides fast IP-to-geo lookup using the SypexGeo binary database (.dat) without external dependencies.
Maintained by GLOBUS.studio and Yevhen Leonidov.
- Pure PHP reader for the SypexGeo database
- PHP 8.0+ compatible (tested on 8.0–8.3)
- File, memory, and batch modes for optimal performance
- Country and City lookups with optional full details (city, region, country)
- No external services required
- PHP 8.0 or higher
- SypexGeo database file (e.g.,
SxGeo.dat)
- Copy
SypexGeo.phpand yourSxGeo.datdatabase file into your project. - Include the class and instantiate it in your code.
require __DIR__ . '/SypexGeo.php';
// Modes: SXGEO_FILE (default), SXGEO_MEMORY, SXGEO_BATCH (bit flags)
$SxGeo = new SxGeo('SxGeo.dat', SXGEO_FILE);
$iso = $SxGeo->getCountry('8.8.8.8'); // e.g. "US"
$id = $SxGeo->getCountryId('8.8.8.8'); // internal country ID
$city = $SxGeo->getCity('8.8.8.8'); // [ 'city' => ..., 'country' => ... ]
$full = $SxGeo->getCityFull('8.8.8.8'); // [ 'city' => ..., 'region' => ..., 'country' => ... ]
$meta = $SxGeo->about(); // database metadata$SxGeo = new SxGeo('SxGeo.dat', SXGEO_MEMORY | SXGEO_BATCH);
// MEMORY keeps DB in RAM for fastest lookups; BATCH optimizes index searches.get(string $ip): Returns city structure if city DB is present, otherwise country code.getCountry(string $ip): ISO 3166-1 alpha-2 country code (e.g., "US").getCountryId(string $ip): Internal numeric country ID.getCity(string $ip): Array with keyscityandcountry.getCityFull(string $ip): Array withcity,region, andcountry.about(): Array with database metadata (type, charset, sizes, etc.).
- IPv4 only. Private/reserved ranges return
false. - Make sure your
SxGeo.datmatches the reader (Country/City/City Max variants). - Keep the database up to date. See the official SypexGeo resources for the latest databases.
MIT License — see the LICENSE file.
- GLOBUS.studio
- Yevhen Leonidov
Credits to the original SypexGeo project and its authors.