Discuz教程网

PHP 检测手机浏览器的代码

[复制链接]
authicon dly 发表于 2011-3-22 23:18:28 | 显示全部楼层 |阅读模式
  1. <?php function is_mobile(){ // returns true if one of the specified mobile browsers is detected $regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|"; $regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|"; $regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|"; $regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|"; $regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220"; $regex_match.=")/i"; return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT'])); } /* allow the user a way to force either the full or mobile versions of the site - use a GET parameter on requests: include likes to both versions of the site w/ the special force mode parameters, 'mobile' and 'full': <a href="http://www.example.org/?mobile">View Mobile Site</a> <a href="http://www.example.org/?full">View Full Site</a> Always check for 'mobile' or 'full' parameters before accounting for any User-Agent conditions: */ if ($_GET['mobile']) { $is_mobile = true; } if ($_GET['full']) { $is_mobile = false; } if($is_mobile) { //it's a mobile browser, do something header("Location: http://www.yoursite.com/mobile"); } else { //it's not a mobile browser, do something else header("Location: http://www.yoursite.com/desktop"); // or instead of a redirect, simply build html below } ?>
复制代码






上一篇:PHP应用中的八种常见文件操作方式
下一篇:PHP与SQL注入攻击
authicon 计晨 发表于 2011-5-7 04:59:57 | 显示全部楼层
好像不错的样子
authicon YY大兔子 发表于 2011-5-8 16:59:42 | 显示全部楼层
不错,我喜欢
authicon mjz 发表于 2011-5-14 00:00:02 | 显示全部楼层
顶的就是你
authicon 月之海洋 发表于 2011-5-18 05:59:48 | 显示全部楼层
不错,我喜欢
authicon 21585151 发表于 2011-5-20 22:59:39 | 显示全部楼层
顶顶更健康
authicon 蓝天blue 发表于 2011-5-25 18:59:55 | 显示全部楼层
喜欢喜欢喜欢
authicon cutiemimi 发表于 2011-6-21 02:59:36 | 显示全部楼层
不错不错,我喜欢
authicon icenna 发表于 2011-6-22 21:59:47 | 显示全部楼层
不错,我喜欢
authicon lightning123 发表于 2011-6-25 07:59:43 | 显示全部楼层
真的有意思!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-6-19 22:20

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表