用于检测移动或选项卡的 PHP 代码


Php code to detect mobilie or tab

我已经下载了一个php代码来检测设备(意味着手机或平板电脑)。它正在工作核心,但是。但是在检测到我何时尝试重定向到另一个页面后,它不起作用

这是我调用的检测方法

代码如下

$detec=detectBrowser();
if($detec==true)
{   
header("location: http://www.google.com"); 
}

它正在打印你好,但不是重定向。

PHP 文件的第二行(<?php 之后):

// Turn on ALL error reporting
ini_set('display_errors',1); 
error_reporting(E_ALL);

检测代码:

$detect = detectBrowser();
if($detect == true) {
   // The user is using a mobile device. Proceed to the next URL.
   header("Location: http://www.url.com/mobile/");
} else {
   // The user is not using a mobile device.
   header("Location: http://www.url.com/non-mobile/");
}

试试这段代码。它检查用户是否不在移动设备上,重定向到非移动设备,或者如果用户使用的是移动设备,然后转到移动网站。