1. Go to this page and download the library: Download duc_cnzj/ip library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
duc_cnzj / ip example snippets
$client = new IpClient();
$client->setIp('xxx.xxx.xxx.xxx')->getCity();
$client->setIp('xxx.xxx.xxx.xxx')->getCountry();
$client->setIp('xxx.xxx.xxx.xxx')->getRegion();
$client->setIp('xxx.xxx.xxx.xxx')->getIp();
# or
$client->setIp('xxx.xxx.xxx.xxx');
$client->getCity();
$client->city;
# use Provider (baidu, taobao, ali)
$client = new IpClient();
# if use baidu api, you need provide ak secret.
$client->useProvider('baidu')
->setProviderConfig('baidu', ['ak' => 'xxxxxxxxxxxx']);
# or
$client->useProvider('baidu')
->setProviderConfig('baidu', 'xxxxxxxxxxxx');
# if use tencent api, you need provide ak secret.
$client->useProvider('tencent')
->setProviderConfig('tencent', ['key' => 'xxxxxxxxxxxx']);
# or
$client->useProvider('tencent')
->setProviderConfig('tencent', 'xxxxxxxxxxxx');
# mutil set/get configs
$client->setConfigs(['ali' => 'xxxxx', 'baidu' => 'xxxxx']);
$client->getConfigs('ali', 'baidu');
# if use ali api, you need provide ak secret.
$client->useProvider('ali')
->setProviderConfig('ali', ['app_code' => 'xxxxxxxxxxxx']);
# if use taobao.
$client->useProvider('taobao');
# default use all provider. if you want use all, pls set secret for each provider.
$client->setProviderConfig('baidu', ['ak' => 'xxxxxxxxxxxx']);
$client->setProviderConfig('ali', 'xxxxxxxxxxxx');
# package will try 3 times when provider response error. use try method to reset tryTimes.
$client->setIp('xxx.xxx.xxx.xxx')->try(10);
# in laravel
$client = app('ip');
# baidu/ali/tencent return point_x and point_y, so you can:
$client->useProvider('baidu')
->setProviderConfig('baidu', ['ak' => 'xxxxxxxxxxxx']);
$client->useProvider('ali')
->setProviderConfig('ali', ['app_code' => 'xxxxxxxxxxxx']);
$client->useProvider('tencent')
->setProviderConfig('tencent', 'xxxxxxxxxxxx');
$client->getPointX();
$client->getPointY();
# taobao return isp, so u can:
$client->useProvider('taobao')
->setIp('xxx.xxx.xxx.xxx')
->getIsp();
$client->use('taobao', 'baidu'); # It will be executed in the order you passed it in
# Equals to
$client->useProvider('taobao', 'baidu');
$client->clearUse(); # will clear providers;
# custom your instance. need implement DucCnzj\Ip\Imp\IpImp, Object or String.
# if it dont need secret, pls set the third parameter false;
$client->bind('taobao', $taobao);
# set custom CacheStore. default is ArrayStore. need implement DucCnzj\Ip\Imp\CacheStoreImp;
$client->setCacheStore($store);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.