PHP判断浏览器和移动设备手机平板或PC代码

类文件引用:


<?php
/** 
* Mobile Detect Library 
* ===================== 
* 
* Motto: "Every business should have a mobile detection script to detect mobile readers" 
* 
* Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). 
* It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. 
* 
* @author      Current authors: Serban Ghita <serbanghita@gmail.com>, Nick Ilyin <nick.ilyin@gmail.com> 
*              Original author: Victor Stanciu <vic.stanciu@gmail.com> 
* 
* @license     Code and contributions have 'MIT License' 
*              More details: https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt 
* 
* @link        Homepage:     http://mobiledetect.net 
*              GitHub Repo:  https://github.com/serbanghita/Mobile-Detect 
*              Google Code:  http://code.google.com/p/php-mobile-detect/ 
*              README:       https://github.com/serbanghita/Mobile-Detect/blob/master/README.md 
*              HOWTO:        https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples 
* 
* @version     2.8.0 
*/  

class Mobile_Detect  
{  
	/** 
	 * Mobile detection type. 
	 * 
	 * @deprecated since version 2.6.9 
	 */  
	const DETECTION_TYPE_MOBILE     = 'mobile';  

..代码省略部分..

		//All older smartphone platforms and featurephones - Any device that doesn't support media queries  
		//will receive the basic, C grade experience.  
		return self::MOBILE_GRADE_C;  
	}  
}  

?>

DEMO使用方法:


<?php
// Include and instantiate the class.  
require_once 'mobile_detecting.php';  
$detect = new Mobile_Detect;  
   
// Any mobile device (phones or tablets).  
if ( $detect->isMobile() ) {  
	header("Location:http://localhost/mobile.html");
} else {
	header("Location:http://localhost/pc.html");
}

网盘下载

参考原始代码:站点访问设备判断源码下载
网盘下载

相关文章代码:
访问PC或移动设备手机平板电脑判断

郑重声明:

1 本资源来源于互联网,资源的版权归资源原作者所持有,受《中华人民共和国著作权法》等相关法律保护。

2 由于无法和原作者取得联系,所以上传的部分资源无法先通过原作者的同意就分享给大家了,如本资源侵犯了您(原作者)的权益,请联系我们(微信号 xiaohaimei1989),我们会立马删除您的资源,并向您表达诚挚的歉意!

3 本站是一个公益型网站,分享资源的目的在于传播知识,分享知识,收取一点点打赏的辛苦费是用于网站的日常运营开支,并非用于商业用途。

4 本站资源只提供学习和参考研究使用,使用过后请在第一时间内删除。本站不承担资源被单位或个人商用带来的法律责任。

发表评论