123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/6/11
- * Time: 上午9:28
- */
- namespace common\api;
- use Yii;
- class IpInfoServer {
- /*
- * 传入IP地址,返回IP所在地信息
- * */
- public function getIpInfo($ip)
- {
- $data = json_decode(@file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip),true);
- if(!empty($data) && $data['code'] == 0)
- {
- return $data['data'];
- }
- return false;
- }
- public function getUserIp()
- {
- return Yii::$app->request->userIP;
- }
- public static function LimitIp()
- {
- $ip =Yii::$app->request->userIP;
- $curl = new \linslin\yii2\curl\Curl();
- $iphttp = 'http://ossimg.niufangw.com/public/ipadopt?ip='.$ip.'&type=1';
- $ipResult = $curl->get($iphttp);
- if(!empty($ipResult))
- {
- $iprow = json_decode($ipResult,true);
- }
- if(!empty($ip) && (isset($iprow) && $iprow['code'] == 300))
- {
- $http = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
- $result = $curl->get($http);
- if(!empty($result))
- {
- $res = json_decode($result,true);
- if(!empty($res) && $res['code'] == 0 && strpos($res['data']['region'],'海南') !== false)
- {
- header('Location:http://www.baidu.com');
- exit ;
- }
- if(empty($res))
- {
- header('Location:http://www.baidu.com');
- exit ;
- }
- $inputHttp = 'http://ossimg.niufangw.com/public/ipadd?ip='.$ip.'&type=1';
- $curl->get($inputHttp);
- }
- }
- }
- }
|