foursking
V2EX  ›  PHP

求助如何判断访问来源是否为手机,求手机 HTTP_USER_AGENT 列表

  •  
  •   foursking · Feb 10, 2014 · 5927 views
    This topic created in 4499 days ago, the information mentioned may be changed or developed.
    RT,需要判断来源手机(不包括pad !!! ipad 三星系列 ...) 目前想到的方法是整理所有的设备号,然后做过滤. 不知道是否有更好的方法
    10 replies    1970-01-01 08:00:00 +08:00
    zencoding
        3
    zencoding  
       Feb 10, 2014   ❤️ 1
    $mobile_agents = array('w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','oper','palm','pana','pant','phil','play','port','prox','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-'
    );
    explon
        4
    explon  
       Feb 10, 2014   ❤️ 1
    function is_mobile()
    {
    $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);

    if (preg_match('/playstation/i', $user_agent) OR preg_match('/ipad/i', $user_agent) OR preg_match('/ucweb/i', $user_agent))
    {
    return false;
    }

    if (preg_match('/iemobile/i', $user_agent) OR preg_match('/mobile\ssafari/i', $user_agent) OR preg_match('/iphone\sos/i', $user_agent) OR preg_match('/android/i', $user_agent) OR preg_match('/symbian/i', $user_agent) OR preg_match('/series40/i', $user_agent))
    {
    return true;
    }

    return false;
    }
    zenxds
        5
    zenxds  
       Feb 10, 2014   ❤️ 1
    /(iPod|iPhone|Android|Opera Mini|BlackBerry|webOS|UCWEB|Blazer|PSP|IEMobile|Symbian)/gi
    foursking
        6
    foursking  
    OP
       Feb 10, 2014
    @xream pad 系列能过滤掉吗 谢谢
    foursking
        7
    foursking  
    OP
       Feb 10, 2014
    @explon 能否过滤 三星 pad 系列
    foursking
        8
    foursking  
    OP
       Feb 10, 2014
    @megaforce 多谢 测试可以使用
    regent
        9
    regent  
       Feb 10, 2014
    我之前用的一个方法是,把WordPress上面的移动版面插件打开看看,里面有关于UA的判断
    vibbow
        10
    vibbow  
       Feb 11, 2014
    UA识别大全: http://browscap.org/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2249 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 00:52 · PVG 08:52 · LAX 17:52 · JFK 20:52
    ♥ Do have faith in what you're doing.