梦殇国际

标题: PHP判断是否为手机访问 [打印本页]

作者: 阿星    时间: 2015-8-10 23:35
标题: PHP判断是否为手机访问
  1. <?php
  2. // 判断是否属手机的方法
  3. function is_mobile() {
  4.         $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  5.         $mobile_agents = Array (
  6.                         "240x320",
  7.                         "acer",
  8.                         "acoon",
  9.                         "acs-",
  10.                         "abacho",
  11.                         "ahong",
  12.                         "airness",
  13.                         "alcatel",
  14.                         "amoi",
  15.                         "android",
  16.                         "anywhereyougo.com",
  17.                         "applewebkit/525",
  18.                         "applewebkit/532",
  19.                         "asus",
  20.                         "audio",
  21.                         "au-mic",
  22.                         "avantogo",
  23.                         "becker",
  24.                         "benq",
  25.                         "bilbo",
  26.                         "bird",
  27.                         "blackberry",
  28.                         "blazer",
  29.                         "bleu",
  30.                         "cdm-",
  31.                         "compal",
  32.                         "coolpad",
  33.                         "danger",
  34.                         "dbtel",
  35.                         "dopod",
  36.                         "elaine",
  37.                         "eric",
  38.                         "etouch",
  39.                         "fly ",
  40.                         "fly_",
  41.                         "fly-",
  42.                         "go.web",
  43.                         "goodaccess",
  44.                         "gradiente",
  45.                         "grundig",
  46.                         "haier",
  47.                         "hedy",
  48.                         "hitachi",
  49.                         "htc",
  50.                         "huawei",
  51.                         "hutchison",
  52.                         "inno",
  53.                         "ipad",
  54.                         "ipaq",
  55.                         "ipod",
  56.                         "jbrowser",
  57.                         "kddi",
  58.                         "kgt",
  59.                         "kwc",
  60.                         "lenovo",
  61.                         "lg ",
  62.                         "lg2",
  63.                         "lg3",
  64.                         "lg4",
  65.                         "lg5",
  66.                         "lg7",
  67.                         "lg8",
  68.                         "lg9",
  69.                         "lg-",
  70.                         "lge-",
  71.                         "lge9",
  72.                         "longcos",
  73.                         "maemo",
  74.                         "mercator",
  75.                         "meridian",
  76.                         "micromax",
  77.                         "midp",
  78.                         "mini",
  79.                         "mitsu",
  80.                         "mmm",
  81.                         "mmp",
  82.                         "mobi",
  83.                         "mot-",
  84.                         "moto",
  85.                         "nec-",
  86.                         "netfront",
  87.                         "newgen",
  88.                         "nexian",
  89.                         "nf-browser",
  90.                         "nintendo",
  91.                         "nitro",
  92.                         "nokia",
  93.                         "nook",
  94.                         "novarra",
  95.                         "obigo",
  96.                         "palm",
  97.                         "panasonic",
  98.                         "pantech",
  99.                         "philips",
  100.                         "phone",
  101.                         "pg-",
  102.                         "playstation",
  103.                         "pocket",
  104.                         "pt-",
  105.                         "qc-",
  106.                         "qtek",
  107.                         "rover",
  108.                         "sagem",
  109.                         "sama",
  110.                         "samu",
  111.                         "sanyo",
  112.                         "samsung",
  113.                         "sch-",
  114.                         "scooter",
  115.                         "sec-",
  116.                         "sendo",
  117.                         "sgh-",
  118.                         "sharp",
  119.                         "siemens",
  120.                         "sie-",
  121.                         "softbank",
  122.                         "sony",
  123.                         "spice",
  124.                         "sprint",
  125.                         "spv",
  126.                         "symbian",
  127.                         "tablet",
  128.                         "talkabout",
  129.                         "tcl-",
  130.                         "teleca",
  131.                         "telit",
  132.                         "tianyu",
  133.                         "tim-",
  134.                         "toshiba",
  135.                         "tsm",
  136.                         "up.browser",
  137.                         "utec",
  138.                         "utstar",
  139.                         "verykool",
  140.                         "virgin",
  141.                         "vk-",
  142.                         "voda",
  143.                         "voxtel",
  144.                         "vx",
  145.                         "wap",
  146.                         "wellco",
  147.                         "wig browser",
  148.                         "wii",
  149.                         "windows ce",
  150.                         "wireless",
  151.                         "xda",
  152.                         "xde",
  153.                         "zte"
  154.         );
  155.         $is_mobile = false;
  156.         foreach ( $mobile_agents as $device ) {
  157.                 if (stristr ( $user_agent, $device )) {
  158.                         $is_mobile = true;
  159.                         break;
  160.                 }
  161.         }
  162.         return $is_mobile;
  163. }
  164. // 调用判断方法
  165. if (is_mobile ()) {
  166.         // 如果是手机,your code
  167. } else {
  168.         // 如果不是手机,your code
  169. }
  170. ?>
复制代码
这个方法适用于任何PHP网站。今天用到了就分享一下。各位晚安


作者: 荣辱    时间: 2015-8-10 23:39
前排

作者: 上杉桃子    时间: 2015-8-10 23:42
好厉害的样子

作者: 青青子衿。    时间: 2015-8-10 23:45
这是

作者: 鬼鬼    时间: 2015-8-10 23:47
你发的都太深奥!!

作者: 栗栗栗子    时间: 2015-8-10 23:47
看不懂就凑个热闹0.0

作者: 凉    时间: 2015-8-10 23:49
阿星大大你真的是女的么(°ー°〃)

作者: smoke    时间: 2015-8-10 23:53
这里竟然木有iPhone

作者: 帅比丶耗子    时间: 2015-8-11 00:04
乐视查到code有什么用

作者: 落红尘    时间: 2015-8-11 07:50
看不懂……

作者: 阿星    时间: 2015-8-11 12:30
smoke 发表于 2015-8-10 23:53
这里竟然木有iPhone

"applewebkit/525",
"applewebkit/532",

貌似这就是吧

作者: 阿星    时间: 2015-8-11 12:30
帅比丶耗子 发表于 2015-8-11 00:04
乐视查到code有什么用

电脑一个页面,手机一个页面什么的,就用得到这个

作者: smoke    时间: 2015-8-11 12:41
阿星 发表于 2015-8-11 12:30
"applewebkit/525",
"applewebkit/532",

好像是

作者: 阿星    时间: 2015-8-11 12:46
smoke 发表于 2015-8-11 12:41
好像是

直接判断的浏览器

作者: smoke    时间: 2015-8-11 12:50
阿星 发表于 2015-8-11 12:46
直接判断的浏览器

原来如此

作者: beibeifatie2    时间: 2015-12-31 22:41
等一等在shuashua吧





欢迎光临 梦殇国际 (https://714.hk/) Powered by Discuz! X3.4