PHP检测终端设备是平板、手机还是电脑
2015-11-17 11:02
651 查看
<?php $ua = $_SERVER['HTTP_USER_AGENT']; function userAgent($ua){ $iphone = strstr(strtolower($ua), 'mobile'); //Search for 'mobile' in user-agent (iPhone have that) $android = strstr(strtolower($ua), 'android'); //Search for 'android' in user-agent $windowsPhone = strstr(strtolower($ua), 'phone'); //Search for 'phone' in user-agent (Windows Phone uses that) function androidTablet($ua){ //Find out if it is a tablet if(strstr(strtolower($ua), 'android') ){//Search for android in user-agent if(!strstr(strtolower($ua), 'mobile')){ //If there is no ''mobile' in user-agent (Android have that on their phones, but not tablets) return true; } } } $androidTablet = androidTablet($ua); //Do androidTablet function $ipad = strstr(strtolower($ua), 'ipad'); //Search for iPad in user-agent if($androidTablet || $ipad){ //If it's a tablet (iPad / Android) return 'tablet'; } elseif($iphone && !$ipad || $android && !$androidTablet || $windowsPhone){ //If it's a phone and NOT a tablet return 'mobile'; } else{ //If it's not a mobile device return 'desktop'; } } echo userAgent($ua); /* 判断可以继续跳转到对应的域名 */ //判断如果当前设备不是电脑访问,则跳转到wap;如果当前设备是电脑访问,则跳转到www if(userAgent($ua) != 'desktop'){
location ='http://wap.baidu.com'+window.location.pathname; } else { location ='http://www.baidu.com'+window.location.pathname; }
?>
相关文章推荐
- ThinkPHP3.1.3的学习之路(1)
- PHP里10个鲜为人知但却非常有用的函数
- 直接拿来用 九个超实用的PHP代码片段(二)
- PHP 如何阻止用户上传成人照片或者裸照
- yii2 log的使用
- thinkcmf (thinkphp) 集成 ping++
- yii2 save update 数组赋值操作
- Editplus个人喜好设置
- thinkphp url链接自动被加上了后缀html(如何修改)
- 理解 PHP 中的 Streams
- php面向对象实现简单的用户注册登陆
- Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)开发环境
- JAVA+PHP+阿里云组件纯手工实现POP、SMTP、IMAP开发邮件服务器(一)
- PHPSTORM/IntelliJ IDEA 常用 设置配置优化 - meetrice
- FileInputStream FileOutputStream
- PHP运行模式
- 遇到的问题:PHPNOW修改虚拟主机失败
- phpstorm的设置
- Simplexml_load_string函数解析xml
- firstProject