Skip to content

Commit

Permalink
Added IP2Location web service.
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location authored Aug 25, 2020
1 parent a2c8d65 commit 429072b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
71 changes: 64 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ IP2Location Laravel extension enables the user to find the country, region, city
4. Download IP2Location BIN database
- IP2Location free LITE database at https://lite.ip2location.com
- IP2Location commercial database at https://www.ip2location.com
5. Create a folder named as `ip2location` in the `database` directory.
5. To use IP2Location databases, create a folder named as `ip2location` in the `database` directory.
6. Unzip and copy the BIN file into `database/ip2location/` folder.
7. Rename the BIN file to IP2LOCATION.BIN.
8. To use IP2Location web service, create a new file called "site_vars.php" in `config` directory.
9. In the site_vars.php, save the following contents:
```php
<?php
return [
'IP2LocationAPIKey' => 'your_api_key', // Required. Your IP2Location API key.
'IP2LocationPackage' => 'WS1', // Required. Choose the package you would like to use.
'IP2LocationUsessl' => false, // Optional. Use https or http.
'IP2LocationAddons' => [], // Optional. Refer to https://www.ip2location.com/web-service/ip2location for the list of available addons.
'IP2LocationLanguage' => 'en', // Optional. Refer to https://www.ip2location.com/web-service/ip2location for available languages.
];
```


## USAGE
Expand All @@ -29,8 +41,8 @@ In this tutorial, we will show you on how to create a **TestController** to disp
php artisan make:controller TestController
```
2. Open the **app/Http/Controllers/TestController.php** in any text editor.
3. Add the below lines into the controller file.
```
3. To use IP2Location databases, add the below lines into the controller file.
```php
<?php

namespace App\Http\Controllers;
Expand All @@ -41,7 +53,8 @@ use IP2LocationLaravel; //use IP2LocationLaravel class
class TestController extends Controller
{
//Create a lookup function for display
public function lookup(){
public function lookup(){

//Try query the geolocation information of 8.8.8.8 IP address
$records = IP2LocationLaravel::get('8.8.8.8');

Expand Down Expand Up @@ -71,18 +84,62 @@ class TestController extends Controller
}
}
```
4. Add the following line into the *routes/web.php* file.
4. To use IP2Location databases, add the below lines into the controller file.
```php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use IP2LocationLaravel; //use IP2LocationLaravel class

class TestController1 extends Controller
{
//Create a lookup function for display
public function lookup(){
//Try query the geolocation information of 8.8.8.8 IP address
$records = IP2LocationLaravel::query('8.8.8.8', \Config::get('site_vars.IP2LocationAPIKey'), \Config::get('site_vars.IP2LocationPackage'), \Config::get('site_vars.IP2LocationUsessl'), \Config::get('site_vars.IP2LocationAddons'), \Config::get('site_vars.IP2LocationLanguage'));

echo 'Country Code : ' . $records['country_code'] . "<br>";
echo 'Country Name : ' . $records['country_name'] . "<br>";
echo 'Region Name : ' . $records['region_name'] . "<br>";
echo 'City Name : ' . $records['city_name'] . "<br>";
echo 'Latitude : ' . $records['latitude'] . "<br>";
echo 'Longitude : ' . $records['longitude'] . "<br>";
echo 'Area Code : ' . $records['area_code'] . "<br>";
echo 'IDD Code : ' . $records['idd_code'] . "<br>";
echo 'Weather Station Code : ' . $records['weather_station_code'] . "<br>";
echo 'Weather Station Name : ' . $records['weather_station_name'] . "<br>";
echo 'MCC : ' . $records['mcc'] . "<br>";
echo 'MNC : ' . $records['mnc'] . "<br>";
echo 'Mobile Carrier : ' . $records['mobile_brand'] . "<br>";
echo 'Usage Type : ' . $records['usage_type'] . "<br>";
echo 'Elevation : ' . $records['elevation'] . "<br>";
echo 'Net Speed : ' . $records['net_speed'] . "<br>";
echo 'Time Zone : ' . $records['time_zone'] . "<br>";
echo 'ZIP Code : ' . $records['zip_code'] . "<br>";
echo 'Domain Name : ' . $records['domain'] . "<br>";
echo 'ISP Name : ' . $records['isp'] . "<br>";
echo 'Credits Consumed : ' . $records['credits_consumed'] . "<br>";
}
}

```
5. Add the following line into the *routes/web.php* file.
```
Route::get('test', 'TestController@lookup');
```
5. Enter the URL <your domain>/public/test and run. You should see the information of **8.8.8.8** IP address.

## DEPENDENCIES (IP2LOCATION BIN DATA FILE)
## DEPENDENCIES

This library requires IP2Location BIN data file to function. You may download the BIN data file at
This library requires either IP2Location BIN data file or IP2Location API key to function. You may download the BIN data file at
* IP2Location LITE BIN Data (Free): https://lite.ip2location.com
* IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com

For IP2Location API key, you can sign up [IP2Location Web Service](https://www.ip2location.com/web-service/ip2location) to get one free API key.

## IPv4 BIN vs IPv6 BIN

Use the IPv4 BIN file if you just need to query IPv4 addresses.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"keywords": [
"laravel",
"laravel 5",
"laravel 7",
"IP2Location",
"geolocation"
],
Expand Down
2 changes: 1 addition & 1 deletion license.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 IP2Location.com
Copyright (c) 2020 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
Expand Down

0 comments on commit 429072b

Please sign in to comment.