emlog判断是否为手机浏览器
emlog利用函数判断客户端是否为手机浏览器:
打开模板的 module.php,添加下面的代码:
<?php function is_mobile() { $user_agent = $_SERVER['HTTP_USER_AGENT']; $mobile_browser = Array( "mqqbrowser", //手机QQ浏览器 "opera mobi", //手机opera "juc","iuc",//uc浏览器 "fennec","ios","applewebKit/420","applewebkit/525","applewebkit/532","ipad","iphone","ipaq","ipod", "iemobile", "windows ce",//windows phone "240×320","480×640","acer","android","anywhereyougo.com","asus","audio","blackberry","blazer","coolpad" ,"dopod", "etouch", "hitachi","htc","huawei", "jbrowser", "lenovo","lg","lg-","lge-","lge", "mobi","moto","nokia","phone","samsung","sony","symbian","tablet","tianyu","wap","xda","xde","zte" ); $is_mobile = false; foreach ($mobile_browser as $device) { if (stristr($user_agent, $device)) { $is_mobile = true; break; } } return $is_mobile; }?>
is_mobile()函数返回布尔值,一般用法是在内容页面判断是否手机浏览器:
<?php if(is_mobile()):?> //只有手机客户端才输出 ... ... <?php endif; ?> <?php if(!is_mobile()):?> //只有非手机客户端才输出 ... ... <?php endif; ?>
自己试试吧~
点赞1
支持一下