ysenn / ip2region
Locate the province, city, and coordinates (latitude and longitude) based on an IP address.
v2.0.1
2025-09-15 07:48 UTC
Requires
- php: >=7.2
- ext-curl: *
- ext-zip: *
- ip2location/ip2location-php: >=9.7
README
Locate the province, city, and coordinates (latitude and longitude) based on an IP address.
Examples
// First use // View command help // Initialize the IP database php vendor/ysenn/ip2region/db_download.php -h // ip2region use IP2Region\IP2Region; // IPv4-only support $ip2region = new IP2Region(); // ip database file loading methods // $ip2region->loadDBModel(IP2Region::VECTOR_INDEX); // loading ip database file $ip2region->loadDBFile(); // output raw data //$ip2region->outputRawData(); return $ip2region->search('127.0.0.1'); // ip2location use IP2Region\IP2Location; // Dual-stack support $ip2location = new IP2Location(); // loading ip database file $ip2location->loadDBFile(); // output raw data //$ip2location->outputRawData(); return $ip2location->search('127.0.0.1'); //return $ip2location->search('2001:0db8:85a3:0000:0000:8a2e:0370:7334'); // ipv6
Third-Party Libraries & Data
This project relies on several fantastic third-party resources.
-
[ip2region]
-
[IP2Location LITE]
- Link: IP2Location LITE
- Purpose: This project uses the IP2Location LITE database as its data source.
- License:
IP2LOCATION LITE DATA LICENSE TERMS OF USE Copyright (c) 2025 IP2Location.com. All Rights Reserved. This download is provided free of charge by IP2Location.com under the following conditions: 1. You must agree to our "Terms of Use", which are published online at https://lite.ip2location.com/terms-of-use at all times. 2. You are not permitted to redistribute or resell this product. 3. The use of "IP2Location.com" to endorse or promote products derived from this database is prohibited without specific prior written permission. 5. Licensees may copy, distribute, display, and perform the work and create derivative works based on IP2Location LITE only if they give IP2LOCATION.COM credits in the manner specified below. All sites, advertising materials, and documentation mentioning features or the use of this database must display the following acknowledgment: "[Your site name or product name] uses the IP2Location LITE database for <a href="https://lite.ip2location.com">IP geolocation</a>." IP2Location is a registered trademark of Hexasoft Development Sdn Bhd. All other trademarks are the property of their respective owners.