|
| 1 | +# Quickstart |
| 2 | + |
| 3 | +## Dependencies |
| 4 | + |
| 5 | +This library requires IP2Location BIN database to function. You may download the BIN database at |
| 6 | + |
| 7 | +- IP2Location LITE BIN Data (Free): <https://lite.ip2location.com> |
| 8 | +- IP2Location Commercial BIN Data (Comprehensive): |
| 9 | + <https://www.ip2location.com> |
| 10 | + |
| 11 | +:::{note} |
| 12 | +An outdated BIN database was provided in the data folder for your testing. You are recommended to visit the above links to download the latest BIN database. |
| 13 | +::: |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +Install this package using the command as below: |
| 18 | + |
| 19 | +``` |
| 20 | +composer require ip2location/ip2proxy-php |
| 21 | +``` |
| 22 | + |
| 23 | +## Sample Codes |
| 24 | + |
| 25 | +### Query geolocation information from BIN database |
| 26 | + |
| 27 | +You can query the geolocation information from the IP2Location BIN database as below: |
| 28 | + |
| 29 | +```php |
| 30 | +require 'vendor/autoload.php'; |
| 31 | + |
| 32 | +$db = new \IP2Proxy\Database('vendor/ip2location/ip2proxy-php/data/PX11.SAMPLE.BIN', \IP2PROXY\Database::FILE_IO); |
| 33 | + |
| 34 | +$records = $db->lookup('1.0.0.8', \IP2PROXY\Database::ALL); |
| 35 | + |
| 36 | +echo '<p><strong>IP Address: </strong>' . $records['ipAddress'] . '</p>'; |
| 37 | +echo '<p><strong>IP Number: </strong>' . $records['ipNumber'] . '</p>'; |
| 38 | +echo '<p><strong>IP Version: </strong>' . $records['ipVersion'] . '</p>'; |
| 39 | +echo '<p><strong>Country Code: </strong>' . $records['countryCode'] . '</p>'; |
| 40 | +echo '<p><strong>Country: </strong>' . $records['countryName'] . '</p>'; |
| 41 | +echo '<p><strong>State: </strong>' . $records['regionName'] . '</p>'; |
| 42 | +echo '<p><strong>City: </strong>' . $records['cityName'] . '</p>'; |
| 43 | + |
| 44 | +/* |
| 45 | + Type of proxy: VPN, TOR, DCH, PUB, WEB, RES (RES available in PX11 only) |
| 46 | +*/ |
| 47 | +echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>'; |
| 48 | + |
| 49 | +/* |
| 50 | + Returns -1 on errors |
| 51 | + Returns 0 is not proxy |
| 52 | + Return 1 if proxy |
| 53 | + Return 2 if it's data center IP |
| 54 | +*/ |
| 55 | +echo '<p><strong>Is Proxy: </strong>' . $records['isProxy'] . '</p>'; |
| 56 | +echo '<p><strong>ISP: </strong>' . $records['isp'] . '</p>'; |
| 57 | +echo '<p><strong>Domain: </strong>' . $records['domain'] . '</p>'; |
| 58 | +echo '<p><strong>Usage Type: </strong>' . $records['usageType'] . '</p>'; |
| 59 | +echo '<p><strong>ASN: </strong>' . $records['asn'] . '</p>'; |
| 60 | +echo '<p><strong>AS: </strong>' . $records['as'] . '</p>'; |
| 61 | +echo '<p><strong>Last Seen: </strong>' . $records['lastSeen'] . '</p>'; |
| 62 | +echo '<p><strong>Threat: </strong>' . $records['threat'] . '</p>'; |
| 63 | +echo '<p><strong>Provider: </strong>' . $records['provider'] . '</p>'; |
| 64 | +``` |
0 commit comments