zoukankan      html  css  js  c++  java
  • 通过IP判断来源

    1. function detect_city($ip) {  
    2.   
    3.         $default = 'UNKNOWN';  
    4.   
    5.         if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost')  
    6.             $ip = '8.8.8.8';  
    7.   
    8.         $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';  
    9.   
    10.         $url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip);  
    11.         $ch = curl_init();  
    12.   
    13.         $curl_opt = array(  
    14.             CURLOPT_FOLLOWLOCATION  => 1,  
    15.             CURLOPT_HEADER      => 0,  
    16.             CURLOPT_RETURNTRANSFER  => 1,  
    17.             CURLOPT_USERAGENT   => $curlopt_useragent,  
    18.             CURLOPT_URL       => $url,  
    19.             CURLOPT_TIMEOUT         => 1,  
    20.             CURLOPT_REFERER         => 'http://' . $_SERVER['HTTP_HOST'],  
    21.         );  
    22.   
    23.         curl_setopt_array($ch, $curl_opt);  
    24.   
    25.         $content = curl_exec($ch);  
    26.   
    27.         if (!is_null($curl_info)) {  
    28.             $curl_info = curl_getinfo($ch);  
    29.         }  
    30.   
    31.         curl_close($ch);  
    32.   
    33.         if ( preg_match('{<li>City : ([^<]*)</li>}i', $content, $regs) )  {  
    34.             $city = $regs[1];  
    35.         }  
    36.         if ( preg_match('{<li>State/Province : ([^<]*)</li>}i', $content, $regs) )  {  
    37.             $state = $regs[1];  
    38.         }  
    39.   
    40.         if( $city!='' && $state!='' ){  
    41.           $location = $city . ', ' . $state;  
    42.           return $location;  
    43.         }else{  
    44.           return $default;  
    45.         }  
    46.   
    47.     }  
  • 相关阅读:
    switch case 变量初始化问题
    GDB 调试 ---转 比较全的东东
    mount不是很熟悉 转载文章了解下 转自http://forum.ubuntu.org.cn/viewtopic.php?f=120&t=257333
    转 strace
    Mysql 漏洞利用(越权读取文件,实战怎么从低权限拿到root密码)[转]
    echo,die(),print(),print_r(),var_dump()的区别
    iis7.5加fck解析漏洞后台拿shell
    Php发送post请求方法
    分享PHP小马一枚,完美绕过安全狗检测。
    性能测试-Gatling(一)
  • 原文地址:https://www.cnblogs.com/yixing/p/9013834.html
Copyright © 2011-2022 走看看