类文件引用:
<?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或移动设备手机平板电脑判断