用于检测移动设备或标签的PHP代码

时间:2013-10-01 13:42:38

标签: php

我已经下载了一个用于检测设备的PHP代码(意味着移动设备或平板电脑)。它正在运作coreect但是。但在检测到我试图重定向到另一个页面后,它无法正常工作

Here is the detect method i have call

,代码在

下面
$detec=detectBrowser();
if($detec==true)
{   

header("location: http://www.google.com"); 
}

打印你好,但没有重定向。

1 个答案:

答案 0 :(得分:0)

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/");
}

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