QQwry.dat纯真IP数据库获取网站访客IP

    //获取IP
    function getIp(){
    $ip = '';
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }elseif(isset($_SERVER['HTTP_CLIENT_IP'])){
    $ip = $_SERVER['HTTP_CLIENT_IP'];
    }else{
    $ip = $_SERVER['REMOTE_ADDR'];
    }
    $ip_arr = explode(',', $ip);
    return $ip_arr[0];
    }
    $ip = getIP();

    //查询ip对应城市

    function ipcityindex(){
    global $ip;
    global $site;

    // $filename = "http://ip.taobao.com/service/getIpInfo.php?ip=".GetIP(); 旧的淘宝接口

    $filename = "http://".$site."/ip.php?ip=".GetIP();
    $json = json_decode(file_get_contents($filename));
    $ipcity= $json->data->city;
    $lens=mb_strlen($ipcity,"UTF8");
    $wcity=mb_substr($ipcity,0,$lens,'utf8');
    return $wcity;
    }
    ----------------------------------------------------------------------------------
    //ip.php
    <?php
    error_reporting(0);
    header("Content-Type: text/html;charset=utf-8");
    function getIp(){
    $ip = '';
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }elseif(isset($_SERVER['HTTP_CLIENT_IP'])){
    $ip = $_SERVER['HTTP_CLIENT_IP'];
    }else{
    $ip = $_SERVER['REMOTE_ADDR'];
    }
    $ip_arr = explode(',', $ip);
    return $ip_arr[0];
    }

    $username="";
    $ip=$_GET['ip'];
    if($ip==""){$ip = getIP();};
    if(!preg_match("/^[\d]+\.[\d]+\.[\d]+\.[\d]+$/isU",$ip)){
    $username = 'IP地址错误';
    }else{
    require_once 'IpLocation.php';
    $setip=new cls_ipAddress("qqwry.dat");
    $location=$setip->getlocation($ip);
    $str=$location['area'];
    $str=iconv("gb2312", "utf-8//IGNORE",$str); //这边纯真IP数据库获取到的gb2312格式的文字,要先转成UTF8
    preg_match_all('/(.*?)省(.*?)市/',$str,$userLocation);
    if (is_array($userLocation)) {
    $province = $userLocation[1][0];
    $city = $userLocation[2][0];
    }
    if($province==""){
    preg_match_all('/(.*?)省/',$str,$userLocation);
    $province = $userLocation[1][0];
    }
    if($city==""){
    preg_match_all('/(.*?)市/',$str,$userLocation);
    if($province==""){
    $province = $userLocation[1][0];
    }
    $city = $userLocation[1][0];
    }
    $username = $province. $city ;
    //echo  $username;
    $operators=$location['operators'];
    $operators=iconv("gb2312", "utf-8//IGNORE",$operators); //这边纯真IP数据库获取到的gb2312格式的文字,要先转成UTF8
    echo '{"code":0,"data":{"ip":"'.$ip.'","area":"'.$str.'","region":"'.$province.'","city":"'.$city.'","operators":"'.$operators.'"}}';
    }
    ?>

    本博客所有文章如无特别注明均为原创。
    复制或转载请以超链接形式注明转自魏枫伦的博客,原文地址《QQwry.dat纯真IP数据库获取网站访客IP
    标签:
    分享:

还没有人抢沙发呢~