@@ -9,7 +9,7 @@ To begin, an API key is required for this module to function. Find further infor
99## Installation
1010Add the following to your composer.json file:
1111
12- ```
12+ ``` json
1313{
1414 "require" : {
1515 "ip2location/ip2proxy-php-api" : " 1.*"
@@ -19,75 +19,27 @@ Add the following to your composer.json file:
1919
2020## Usage
2121
22- ```
22+ ``` php
2323<?php
2424
25- class IP2ProxyAPI
26- {
27- public $response;
28- public $ipAddress;
29- public $countryCode;
30- public $countryName;
31- public $regionName;
32- public $cityName;
33- public $isp;
34- public $proxyType;
35- public $isProxy;
36-
37- protected $apiKey;
38- protected $useSSL;
39-
40- public function __construct($apiKey = '', $useSSL = false)
41- {
42- $this->apiKey = $apiKey;
43- $this->useSSL = $useSSL;
44- }
45-
46- public function query($ip)
47- {
48- if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
49- return false;
50- }
51-
52- $response = $this->get('http' . (($this->useSSL) ? 's' : '') . '://api.ip2proxy.com/?' . http_build_query([
53- 'key' => $this->apiKey,
54- 'ip' => $ip,
55- 'package' => 'PX4',
56- 'format' => 'json',
57- ]));
58-
59- if (($json = json_decode($response)) === null) {
60- return false;
61- }
62-
63- $this->response = (string) $json->response;
64- $this->countryCode = (string) $json->countryCode;
65- $this->countryName = (string) $json->countryName;
66- $this->regionName = (string) $json->regionName;
67- $this->cityName = (string) $json->cityName;
68- $this->isp = (string) $json->isp;
69- $this->proxyType = (string) $json->proxyType;
70- $this->isProxy = (string) $json->isProxy;
71-
72- return true;
73- }
74-
75- private function get($url)
76- {
77- $ch = curl_init();
78-
79- curl_setopt($ch, CURLOPT_URL, $url);
80- curl_setopt($ch, CURLOPT_FAILONERROR, 1);
81- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
82- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
83- curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-1.0.0');
84- curl_setopt($ch, CURLOPT_TIMEOUT, 3);
85- $response = curl_exec($ch);
86-
87- return $response;
88- }
25+ require 'class.IP2ProxyAPI.php';
26+
27+ $api = new IP2ProxyAPI('YOUR_API_KEY');
28+
29+ if ($api->query('1.2.3.4')) {
30+ echo '<strong >Country Code</strong >: ' . $api->countryCode . '<br >';
31+ echo '<strong >Country Name</strong >: ' . $api->countryName . '<br >';
32+ echo '<strong >Region</strong >: ' . $api->regionName . '<br >';
33+ echo '<strong >City</strong >: ' . $api->cityName . '<br >';
34+ echo '<strong >ISP</strong >: ' . $api->isp . '<br >';
35+ echo '<strong >Domain</strong >: ' . $api->domain . '<br >';
36+ echo '<strong >Usage Type</strong >: ' . $api->usageType . '<br >';
37+ echo '<strong >ASN</strong >: ' . $api->asn . '<br >';
38+ echo '<strong >AS</strong >: ' . $api->as . '<br >';
39+ echo '<strong >Last Seen</strong >: ' . $api->lastSeen . '<br >';
40+ echo '<strong >Proxy Type</strong >: ' . $api->proxyType . '<br >';
41+ echo '<strong >Is Proxy</strong >: ' . $api->isProxy . '<br >';
8942}
90- ?>
9143```
9244
9345
@@ -103,3 +55,25 @@ class IP2ProxyAPI
10355| isp | The service provider name. |
10456| isProxy | YES if the IP is a Proxy. NO if the IP is not a proxy. DCH if the IP belongs to Hosting Provider, Data Center or Content Delivery Network. Note: DCH is only available for PX2, PX3 and PX4 query |
10557| proxyType | The type of proxy service. |
58+ | domain | Internet domain name associated with IP address range. |
59+ | usageType | Usage type classification of ISP or company. Refer ** Usage Type** section. |
60+ | asn | Autonomous system number (ASN). |
61+ | as | Autonomous system (AS) name. |
62+ | lastSeen | Proxy last seen in days. |
63+
64+
65+
66+ ##### Usage Type
67+
68+ - (COM) Commercial
69+ - (ORG) Organization
70+ - (GOV) Government
71+ - (MIL) Military
72+ - (EDU) University/College/School
73+ - (LIB) Library
74+ - (CDN) Content Delivery Network
75+ - (ISP) Fixed Line ISP
76+ - (MOB) Mobile ISP
77+ - (DCH) Data Center/Web Hosting/Transit
78+ - (SES) Search Engine Spider
79+ - (RSV) Reserved
0 commit comments