使用php获取设备的源代码
我需要在使用php获取设备的源代码,php,css,Php,Css,我需要在php中找到一种方法,以便能够知道我的网站何时在手机/平板电脑上打开。我需要每个设备(iPhone、android和平板电脑)的具体设计 我已经试过了,但它不能正常工作: <?php if(stristr($_SERVER['HTTP_USER_AGENT'], "Mobile")) { // if mobile browser ?> <link rel="stylesheet" href="<?php
php
中找到一种方法,以便能够知道我的网站何时在手机/平板电脑上打开。我需要每个设备(iPhone、android和平板电脑)的具体设计
我已经试过了,但它不能正常工作:
<?php if(stristr($_SERVER['HTTP_USER_AGENT'], "Mobile"))
{ // if mobile browser ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/mobile.css" type="text/css" media="screen" />
<?php }
使用上述两种样式表。因此,如果设备宽度为800px或更小,则将使用mobile.css进行渲染。或者默认情况下使用style.css 为此,您可以使用php库:
https://github.com/serbanghita/Mobile-Detect
它有很多功能来检测任何设备,例如:isMobile(),isTablet(),isiPhone()等
仅适用于php:
<?php
// include library file
require_once 'Mobile_Detect.php';
$object = new Mobile_Detect;
//Now detect device
<?php
// Return true or false based on your device
$detect->isMobile();
$detect->isTablet();
<?php
// Suppose you want to check for mobile environment.
if ($detect->isMobile()) {
// Your code here.
}
u可以检查其是否已经有ans
<?php
// include library file
require_once 'Mobile_Detect.php';
$object = new Mobile_Detect;
//Now detect device
<?php
// Return true or false based on your device
$detect->isMobile();
$detect->isTablet();
<?php
// Suppose you want to check for mobile environment.
if ($detect->isMobile()) {
// Your code here.
}