首页 > 解决方案 > 移动和桌面探测器

问题描述

我有一个滑块,每个滑块中都有一个视频,是否可以从移动设备进入时显示图片,如果使用桌面输入显示视频?

标签: phphtmlcss

解决方案


您可以使用此功能来检测设备

public function detectDevice(){

$userAgent = $_SERVER["HTTP_USER_AGENT"];
$devicesTypes = array(
    "computer" => array("msie 10", "msie 9", "msie 8", "windows.*firefox", "windows.*chrome", "x11.*chrome", "x11.*firefox", "macintosh.*chrome", "macintosh.*firefox", "opera"),
    "tablet"   => array("tablet", "android", "ipad", "tablet.*firefox"),
    "mobile"   => array("mobile ", "android.*mobile", "iphone", "ipod", "opera mobi", "opera mini"),
    "bot"      => array("googlebot", "mediapartners-google", "adsbot-google", "duckduckbot", "msnbot", "bingbot", "ask", "facebook", "yahoo", "addthis")
);
foreach($devicesTypes as $deviceType => $devices) {           
    foreach($devices as $device) {
        if(preg_match("/" . $device . "/i", $userAgent)) {
            $deviceName = $deviceType;
        }
    }
}
return ucfirst($deviceName);
}

推荐阅读