承接 ip2location/ip2location-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ip2location/ip2location-laravel

Composer 安装命令:

composer require ip2location/ip2location-laravel

包简介

Lookup for visitor's IP information, such as country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type.

README 文档

README

Latest Stable Version Total Downloads

IP2Location Laravel extension enables the user to find the country, region, district, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, IP address type, IAB advertising category and ASN from IP address using IP2Location database. It has been optimized for speed and memory utilization.

Note: This extension works in Laravel 6, Laravel 7, Laravel 8, Laravel 9, Laravel 10, Laravel 11 and Laravel 12.

INSTALLATION

Run the command: composer require ip2location/ip2location-laravel to download the package into the Laravel platform.

USAGE

IP2Location Laravel extension is able to query the IP address 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.

BIN DATABASE

  1. Download IP2Location BIN database
  2. To use IP2Location databases, create a folder named as ip2location in the database directory.
  3. Unzip and copy the BIN file into database/ip2location/ folder.
  4. Rename the BIN file to IP2LOCATION.BIN.
  5. Create a TestController in Laravel using the below command line
php artisan make:controller TestController
  1. Open the app/Http/Controllers/TestController.php in any text editor.
  2. To use IP2Location databases, add the below lines into the controller file.
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use IP2LocationLaravel;			//use IP2LocationLaravel class

class TestController 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::get('8.8.8.8', 'bin');

		echo 'IP Number             : ' . $records['ipNumber'] . "<br>";
		echo 'IP Version            : ' . $records['ipVersion'] . "<br>";
		echo 'IP Address            : ' . $records['ipAddress'] . "<br>";
		echo 'Country Code          : ' . $records['countryCode'] . "<br>";
		echo 'Country Name          : ' . $records['countryName'] . "<br>";
		echo 'Region Name           : ' . $records['regionName'] . "<br>";
		echo 'City Name             : ' . $records['cityName'] . "<br>";
		echo 'Latitude              : ' . $records['latitude'] . "<br>";
		echo 'Longitude             : ' . $records['longitude'] . "<br>";
		echo 'Area Code             : ' . $records['areaCode'] . "<br>";
		echo 'IDD Code              : ' . $records['iddCode'] . "<br>";
		echo 'Weather Station Code  : ' . $records['weatherStationCode'] . "<br>";
		echo 'Weather Station Name  : ' . $records['weatherStationName'] . "<br>";
		echo 'MCC                   : ' . $records['mcc'] . "<br>";
		echo 'MNC                   : ' . $records['mnc'] . "<br>";
		echo 'Mobile Carrier        : ' . $records['mobileCarrierName'] . "<br>";
		echo 'Usage Type            : ' . $records['usageType'] . "<br>";
		echo 'Elevation             : ' . $records['elevation'] . "<br>";
		echo 'Net Speed             : ' . $records['netSpeed'] . "<br>";
		echo 'Time Zone             : ' . $records['timeZone'] . "<br>";
		echo 'ZIP Code              : ' . $records['zipCode'] . "<br>";
		echo 'Domain Name           : ' . $records['domainName'] . "<br>";
		echo 'ISP Name              : ' . $records['isp'] . "<br>";
		echo 'Address Type          : ' . $records['addressType'] . "<br>";
		echo 'Category              : ' . $records['category'] . "<br>";
		echo 'District              : ' . $records['district'] . "<br>";
		echo 'ASN                   : ' . $records['asn'] . "<br>";
		echo 'AS                    : ' . $records['as'] . "<br>";
	}
}
  1. Add the following line into the routes/web.php file.
Route::get('test', 'App\Http\Controllers\TestController@lookup');
  1. Enter the URL /test and run. You should see the information of 8.8.8.8 IP address.

WEB SERVICE

  1. To use IP2Location.io or IP2Location web service, create a new file called "site_vars.php" in config directory.
  2. In the site_vars.php, save the following contents for IP2Location.io:
<?php
return [
    'IP2LocationioAPIKey' => 'your_api_key', // Required. Your IP2Location.io API key.
    'IP2LocationioLanguage' => 'en', // Optional. Refer to https://www.ip2location.io/ip2location-documentation for available languages.
];

Or save the following contents for IP2Location:

<?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.
];
  1. Create a TestController in Laravel using the below command line
php artisan make:controller TestController
  1. Open the app/Http/Controllers/TestController.php in any text editor.
  2. To use IP2Location databases, add the below lines into the controller file.
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use IP2LocationLaravel;			//use IP2LocationLaravel class

class TestController 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::get('8.8.8.8', 'ws');

		echo '<pre>';
		print_r($records);
		echo '</pre>';
	}
}
  1. Add the following line into the routes/web.php file.
Route::get('test', 'App\Http\Controllers\TestController@lookup');
  1. Enter the URL /test and run. You should see the information of 8.8.8.8 IP address.

IPTOOLS

  1. Create a TestController in Laravel using the below command line
php artisan make:controller TestController
  1. Open the app/Http/Controllers/TestController.php in any text editor.
  2. To use IP2Location IPTools class, add the below lines into the controller file.
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use IP2LocationLaravel;			//use IP2LocationLaravel class

class TestController extends Controller
{
	//Create a lookup function for display
	public function lookup(){

		var_dump(IP2LocationLaravel::isIpv4('8.8.8.8'));echo '<br>';
		var_dump(IP2LocationLaravel::isIpv6('2001:4860:4860::8888'));echo '<br>';
		print_r(IP2LocationLaravel::ipv4ToDecimal('8.8.8.8'));echo '<br>';
		print_r(IP2LocationLaravel::decimalToIpv4(134744072));echo '<br>';
		print_r(IP2LocationLaravel::ipv6ToDecimal('2001:4860:4860::8888'));echo '<br>';
		print_r(IP2LocationLaravel::decimalToIpv6('42541956123769884636017138956568135816'));echo '<br>';
		print_r(IP2LocationLaravel::ipv4ToCidr('8.0.0.0', '8.255.255.255'));echo '<br>';
		print_r(IP2LocationLaravel::cidrToIpv4('8.0.0.0/8'));echo '<br>';
		print_r(IP2LocationLaravel::ipv6ToCidr('2002:0000:0000:1234:abcd:ffff:c0a8:0000', '2002:0000:0000:1234:ffff:ffff:ffff:ffff'));echo '<br>';
		print_r(IP2LocationLaravel::cidrToIpv6('2002::1234:abcd:ffff:c0a8:101/64'));echo '<br>';
		print_r(IP2LocationLaravel::compressIpv6('2002:0000:0000:1234:FFFF:FFFF:FFFF:FFFF'));echo '<br>';
		print_r(IP2LocationLaravel::expandIpv6('2002::1234:FFFF:FFFF:FFFF:FFFF'));echo '<br>';
	}
}
  1. Add the following line into the routes/web.php file.
Route::get('test', 'App\Http\Controllers\TestController@lookup');
  1. Enter the URL /test and run.

DEPENDENCIES

This library requires either IP2Location BIN data file or IP2Location API key to function. You may download the BIN data file at

For IP2Location API key, you can sign up IP2Location Web Service to get one free API key.

IPv4 BIN vs IPv6 BIN

Use the IPv4 BIN file if you just need to query IPv4 addresses. Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

SUPPORT

Email: support@ip2location.com

Website: https://www.ip2location.com

ip2location/ip2location-laravel 适用场景与选型建议

ip2location/ip2location-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 547.23k 次下载、GitHub Stars 达 80, 最近一次更新时间为 2017 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「geolocation」 「laravel」 「ip2location」 「laravel 6」 「laravel 7」 「laravel 8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ip2location/ip2location-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ip2location/ip2location-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 ip2location/ip2location-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 547.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 82
  • 点击次数: 44
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 80
  • Watchers: 7
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-25