zoukankan      html  css  js  c++  java
  • user_agent

    public function getipinfo($ip) {
    $res = '其他';
    $url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=".$ip;
    $ch = curl_init();
    $SSL = substr($url, 0, 8) == "https://" ? true : false;
    if($SSL)
    {
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_HEADER, 0); // 不要http header 加快效率
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $output = curl_exec($ch);
    curl_close($ch);
    $res1 = preg_match("/({.*})/", $output,$matches);
    if($matches){
    $res2 = json_decode($matches[0], true);
    $res = isset($res2['country'])?($res2['province']?$res2['province']:'其他'):'其他';
    }
    return $res;
    }

    private function check_useragent(){
    $os = $browser = $language = '其他';

    if(strpos($_SERVER["HTTP_USER_AGENT"],"iPhone"))
    $os = "iPhone";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Android"))
    $os = "Android";

    if(strpos($_SERVER["HTTP_USER_AGENT"],"MicroMessenger"))
    $browser = "Wechat";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE"))
    $browser = "Internet Explorer";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox"))
    $browser = "Firefox";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Chrome"))
    $browser = "Google Chrome";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Safari"))
    $browser = "Safari";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Opera"))
    $browser = "Opera";

    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); //只取前4位,这样只判断最优先的语言。如果取前5位,可能出现en,zh的情况,影响判断。
    if (preg_match("/zh-c/i", $lang))
    $language = "简体中文";
    else if (preg_match("/zh/i", $lang))
    $language = "繁體中文";
    else if (preg_match("/en/i", $lang))
    $language = "English";
    else if (preg_match("/jp/i", $lang))
    $language = "Japanese";
    else if (preg_match("/ko/i", $lang))
    $language = "Korean";
    return array('os'=>$os,'browser'=>$browser,'language'=>$language);
    }

  • 相关阅读:
    KNN算法
    mysql必须知道的
    励志的演讲
    30条程序员名言警句
    别人的文章:为什么软件开发,人多,事少,还会工作量大?
    分享一个比较受启发的文章“学历代表过去,能力代表现在,学习力代表未来”
    mvc 学前必知
    启动docker容器 防火墙问题报错 ! -i docker0' failed: iptables: No chain/target/match by that name.
    git指令详解总结
    git reset 版本回退的三种用法总结
  • 原文地址:https://www.cnblogs.com/echoshao/p/6479128.html
Copyright © 2011-2022 走看看