Skip to content

Commit

Permalink
First release.
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Sep 14, 2017
0 parents commit c3f5b54
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 IP2Location.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# IP2Proxy CakePHP Plugin
IP2Proxy CakePHP plugin enables the user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits. It lookup the proxy IP address from IP2Proxy BIN Data file. Developers can use the API to query all IP2Proxy BIN databases for applications written using CakePHP.


## INSTALLATION
For CakePHP 3.x

1. Run the command: `composer require ip2location/ip2proxy-cakephp` to download the plugin into the CakePHP 3 platform.
2. Download latest IP2Proxy BIN database
- IP2Proxy free LITE database at http://lite.ip2location.com
- IP2Proxy commercial database at http://www.ip2location.com/proxy-database
3. Unzip and copy the BIN file into *cakephp/vendor/ip2location/ip2proxy-cakephp/src/Data* folder.
4. Rename the BIN file to IP2PROXY.BIN.

**Note:** The plugin has included an old BIN database for your testing and development purpose.
You may want to download a latest copy of BIN database as the URL stated above.
The BIN database refers to the binary file ended with .BIN extension, but not the CSV format.
Please select the right package for download.


## USAGE
In this tutorial, we will show you on how to create a **TestsController** to display the IP information.

1. Create a **TestsController** in CakePHP 3 using the below command line
```
php bin/cake bake controller Tests
```
2. Create an empty **index.ctp** file in *cakephp/src/Template/Tests* folder.
3. Open the **cakephp/src/Controller/TestsController.php** in any text editor.
4. Remove the contents in TestsController.php and add the below lines into the controller file.
```
<?php
namespace App\Controller;
use App\Controller\AppController;
use IP2ProxyCakePHP\Controller\IP2ProxyCoresController;
/**
* Tests Controller
*/
class TestsController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|void
*/
public function index()
{
$IP2Proxy = new IP2ProxyCoresController();
$record = $IP2Proxy->get('1.0.241.135');
echo '<p><strong>IP Address: </strong>' . $record['ipAddress'] . '</p>';
echo '<p><strong>IP Number: </strong>' . $record['ipNumber'] . '</p>';
echo '<p><strong>IP Version: </strong>' . $record['ipVersion'] . '</p>';
echo '<p><strong>Country Code: </strong>' . $record['countryCode'] . '</p>';
echo '<p><strong>Country: </strong>' . $record['countryName'] . '</p>';
echo '<p><strong>State: </strong>' . $record['regionName'] . '</p>';
echo '<p><strong>City: </strong>' . $record['cityName'] . '</p>';
echo '<p><strong>Proxy Type: </strong>' . $record['proxyType'] . '</p>';
echo '<p><strong>Is Proxy: </strong>' . $record['isProxy'] . '</p>';
echo '<p><strong>ISP: </strong>' . $record['isp'] . '</p>';
}
}
```
5. Enter the URL <your domain>/Tests and run. You should see the information of **1.0.241.135** IP address.



## DEPENDENCIES (IP2PROXY BIN DATA FILE)
This library requires IP2Proxy BIN data file to function. You may download the BIN data file at
* IP2Proxy LITE BIN Data (Free): http://lite.ip2location.com
* IP2Proxy Commercial BIN Data (Comprehensive): http://www.ip2location.com/proxy-database

## SUPPORT
Email: support@ip2location.com

Website: http://www.ip2location.com
23 changes: 23 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "ip2location/ip2proxy-cakephp",
"description": "Allow users to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.",
"keywords": ["cakephp", "ip2proxy", "geolocation"],
"homepage": "https://github.com/ip2location/ip2proxy-cakephp",
"license": "MIT",
"authors": [
{
"name": "IP2Location",
"email": "support@ip2location.com"
}
],
"require": {
"php": ">=5.4.0",
"cakephp/cakephp": ">=3.0",
"ip2location/ip2proxy-php": "1.*"
},
"autoload": {
"psr-4": {
"IP2ProxyCakePHP\\": "src"
}
}
}
36 changes: 36 additions & 0 deletions src/Controller/IP2ProxyCoresController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace IP2ProxyCakePHP\Controller;

/**
* IP2ProxyCores Controller
*/
class IP2ProxyCoresController
{

/**
* Index method
*
* @return \Cake\Http\Response|void
*/
public function index()
{
//
}

public function get($ip, $query = array())
{
$obj = new \IP2Proxy\Database();
$obj->open(ROOT . DS . 'vendor' . DS . 'ip2location' . DS . 'ip2proxy-cakephp' . DS . 'src' . DS . 'data' . DS . 'IP2PROXY.BIN', \IP2Proxy\Database::FILE_IO);


try {
$records = $obj->getAll($ip);
} catch (Exception $e) {
return null;
}

$obj->close();
return $records;
}

}
Binary file added src/Data/IP2PROXY.BIN
Binary file not shown.

0 comments on commit c3f5b54

Please sign in to comment.