|
4 | 4 |
|
5 | 5 | IP2Proxy Laravel extension enables the user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.
|
6 | 6 |
|
| 7 | +*Note: This extension works in Laravel 6, Laravel 7 and Laravel 8.* |
| 8 | + |
7 | 9 |
|
8 | 10 | ## INSTALLATION
|
9 | 11 |
|
10 | 12 | 1. Run the command: `composer require ip2location/ip2proxy-laravel` to download the package into the Laravel platform.
|
11 | 13 | 2. Edit `config/app.php` and add the below line in 'providers' section:
|
12 | 14 | `Ip2location\IP2ProxyLaravel\IP2ProxyLaravelServiceProvider::class,`
|
13 | 15 | 3. Then publish the config file by:
|
14 |
| -`php artisan vendor:publish --provider=Ip2location\IP2ProxyLaravel\IP2ProxyLaravelServiceProvider --force` |
15 |
| -4. Download IP2Proxy BIN database |
| 16 | +`php artisan vendor:publish --provider='Ip2location\IP2ProxyLaravel\IP2ProxyLaravelServiceProvider' --force` |
| 17 | + |
| 18 | +## USAGE |
| 19 | + |
| 20 | +IP2Proxy Laravel extension is able to query the IP address proxy information from either BIN database or web service. This section will explain how to use this extension to query from BIN database and web service. |
| 21 | + |
| 22 | +### BIN DATABASE |
| 23 | + |
| 24 | +1. Download IP2Proxy BIN database |
16 | 25 | - IP2Proxy free LITE database at https://lite.ip2location.com
|
17 | 26 | - IP2Proxy commercial database at https://www.ip2location.com/proxy-database
|
18 |
| -5. Create a folder named as `ip2proxy` in the `database` directory. |
19 |
| -6. Unzip and copy the BIN file into `database/ip2proxy/` folder. |
20 |
| -7. Rename the BIN file to IP2PROXY.BIN. |
| 27 | +2. To use IP2Proxy databases, create a folder named as `ip2proxy` in the `database` directory. |
| 28 | +3. Unzip and copy the BIN file into `database/ip2proxy/` folder. |
| 29 | +4. Rename the BIN file to IP2PROXY.BIN. |
| 30 | +5. Create a **TestController** in Laravel using the below command line |
| 31 | +``` |
| 32 | +php artisan make:controller TestController |
| 33 | +``` |
| 34 | +6. Open the **app/Http/Controllers/TestController.php** in any text editor. |
| 35 | +7. To use IP2Proxy databases, add the below lines into the controller file |
| 36 | +```php |
| 37 | +<?php |
21 | 38 |
|
| 39 | +namespace App\Http\Controllers; |
22 | 40 |
|
23 |
| -## USAGE |
| 41 | +use Illuminate\Http\Request; |
| 42 | +use IP2ProxyLaravel; //use IP2ProxyLaravel class |
24 | 43 |
|
25 |
| -In this tutorial, we will show you on how to create a **TestController** to display the IP information. |
| 44 | +class TestController extends Controller |
| 45 | +{ |
| 46 | + //Create a lookup function for display |
| 47 | + public function lookup(){ |
| 48 | + //Try query the geolocation information of 1.2.3.4 IP address |
| 49 | + $records = IP2ProxyLaravel::get('1.2.3.4', 'bin'); |
| 50 | + |
| 51 | + echo '<p><strong>IP Address: </strong>' . $records['ipAddress'] . '</p>'; |
| 52 | + echo '<p><strong>IP Number: </strong>' . $records['ipNumber'] . '</p>'; |
| 53 | + echo '<p><strong>IP Version: </strong>' . $records['ipVersion'] . '</p>'; |
| 54 | + echo '<p><strong>Country Code: </strong>' . $records['countryCode'] . '</p>'; |
| 55 | + echo '<p><strong>Country: </strong>' . $records['countryName'] . '</p>'; |
| 56 | + echo '<p><strong>State: </strong>' . $records['regionName'] . '</p>'; |
| 57 | + echo '<p><strong>City: </strong>' . $records['cityName'] . '</p>'; |
| 58 | + echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>'; |
| 59 | + echo '<p><strong>Is Proxy: </strong>' . $records['isProxy'] . '</p>'; |
| 60 | + echo '<p><strong>ISP: </strong>' . $records['isp'] . '</p>'; |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | +8. Add the following line into the *routes/web.php* file. |
| 65 | +``` |
| 66 | +Route::get('test', 'TestController@lookup'); |
| 67 | +``` |
| 68 | +9. Enter the URL <your domain>/public/test and run. You should see the information of **1.2.3.4** IP address. |
26 | 69 |
|
27 |
| -1. Create a **TestController** in Laravel using the below command line |
| 70 | +### WEB SERVICE |
| 71 | + |
| 72 | +1. To use IP2Proxy Web Service, create a new file called "site_vars.php" in `config` directory. |
| 73 | +2. In the site_vars.php, save the following contents: |
| 74 | +```php |
| 75 | +<?php |
| 76 | +return [ |
| 77 | + 'IP2ProxyAPIKey' => 'your_api_key', // Required. Your IP2Proxy API key. |
| 78 | + 'IP2ProxyPackage' => 'PX1', // Required. Choose the package you would like to use. |
| 79 | + 'IP2ProxyUsessl' => false, // Optional. Use https or http. |
| 80 | +]; |
28 | 81 | ```
|
29 |
| -php artisan make:controller TestController |
| 82 | +3. Create a **TestController** in Laravel using the below command line |
30 | 83 | ```
|
31 |
| -2. Open the **app/Http/Controllers/TestController.php** in any text editor. |
32 |
| -3. Add the below lines into the controller file. |
| 84 | +php artisan make:controller TestController |
33 | 85 | ```
|
| 86 | +4. Open the **app/Http/Controllers/TestController.php** in any text editor. |
| 87 | +5. To use IP2Proxy Web Service, add the below lines into the controller file. |
| 88 | +```php |
34 | 89 | <?php
|
35 | 90 |
|
36 | 91 | namespace App\Http\Controllers;
|
37 | 92 |
|
38 | 93 | use Illuminate\Http\Request;
|
| 94 | + |
39 | 95 | use IP2ProxyLaravel; //use IP2ProxyLaravel class
|
40 | 96 |
|
41 | 97 | class TestController extends Controller
|
42 | 98 | {
|
43 | 99 | //Create a lookup function for display
|
44 |
| - public function lookup(){ |
| 100 | + public function lookup(){ |
45 | 101 | //Try query the geolocation information of 1.2.3.4 IP address
|
46 |
| - $record = IP2ProxyLaravel::get('1.2.3.4'); |
47 |
| -
|
48 |
| - echo '<p><strong>IP Address: </strong>' . $record['ipAddress'] . '</p>'; |
49 |
| - echo '<p><strong>IP Number: </strong>' . $record['ipNumber'] . '</p>'; |
50 |
| - echo '<p><strong>IP Version: </strong>' . $record['ipVersion'] . '</p>'; |
51 |
| - echo '<p><strong>Country Code: </strong>' . $record['countryCode'] . '</p>'; |
52 |
| - echo '<p><strong>Country: </strong>' . $record['countryName'] . '</p>'; |
53 |
| - echo '<p><strong>State: </strong>' . $record['regionName'] . '</p>'; |
54 |
| - echo '<p><strong>City: </strong>' . $record['cityName'] . '</p>'; |
55 |
| - echo '<p><strong>Proxy Type: </strong>' . $record['proxyType'] . '</p>'; |
56 |
| - echo '<p><strong>Is Proxy: </strong>' . $record['isProxy'] . '</p>'; |
57 |
| - echo '<p><strong>ISP: </strong>' . $record['isp'] . '</p>'; |
| 102 | + $records = IP2ProxyLaravel::get('1.2.3.4', 'ws'); |
| 103 | + |
| 104 | + echo '<pre>'; |
| 105 | + print_r($records); |
| 106 | + echo '</pre>'; |
58 | 107 | }
|
59 | 108 | }
|
| 109 | + |
60 | 110 | ```
|
61 |
| -4. Add the following line into the *routes/web.php* file. |
| 111 | +6. Add the following line into the *routes/web.php* file. |
62 | 112 | ```
|
63 | 113 | Route::get('test', 'TestController@lookup');
|
64 | 114 | ```
|
65 |
| -5. Enter the URL <your domain>/public/test and run. You should see the information of **1.2.3.4** IP address. |
| 115 | +7. Enter the URL <your domain>/public/test and run. You should see the information of **1.2.3.4*** IP address. |
66 | 116 |
|
67 | 117 | ## DEPENDENCIES (IP2PROXY BIN DATA FILE)
|
68 | 118 |
|
|
0 commit comments