V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
KiseXu
V2EX  ›  PHP

求一段php判断手机客户端的代码

  •  
  •   KiseXu · 2012-10-17 09:17:57 +08:00 · 3822 次点击
    这是一个创建于 4405 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最好是你现在在使用的,比较靠谱的,O(∩_∩)O~
    4 条回复    1970-01-01 08:00:00 +08:00
    picasso250
        1
    picasso250  
       2012-10-17 17:18:18 +08:00   ❤️ 1
    ming
        2
    ming  
       2012-10-17 17:47:10 +08:00   ❤️ 1
    手机浏览器?
    function is_mobile() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");
    $is_mobile = false;
    foreach ($mobile_agents as $device) {
    if (stristr($user_agent, $device)) {
    $is_mobile = true;
    break;
    }
    }
    return $is_mobile;
    }
    KiseXu
        3
    KiseXu  
    OP
       2012-10-17 21:28:12 +08:00
    @picasso250
    @ming
    非常感谢,测试了,使用正常。
    ps.谢谢 @ming 送的手机,很好用
    anyforever
        4
    anyforever  
       2012-10-26 20:29:43 +08:00   ❤️ 1
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);

    $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";

    if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
    {
    $Loaction = 'mobile/';

    if (!empty($Loaction))
    {
    ecs_header("Location: $Loaction\n");

    exit;
    }

    }

    via ecshop
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1115 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 18:49 · PVG 02:49 · LAX 10:49 · JFK 13:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.