我试图传递的字符串是"www.he2media.com/index.php?mobile=false"我做错了什么?
<?PHP
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
$ismobiledevice;
if($_GET['mobile']=== "")
{
$ismobiledevice=0;
}
if($_GET['mobile']==="false")
{
$ismobiledevice=1;
}
if($detect->isMobile()&& empty($ismobiledevice))
{
header("Location:http://m.he2media.com");
}
else
{
header("Location:http://www.he2media.com");
}
?>
您实际上不是在传递字符串,而是在设置标头位置。
也许您应该在Location:
和URL之间添加一个空格:
header("Location: http://...");
你的if
正在做与它应该做的事情相反的事情
if($_GET['mobile']=== ""){
$ismobiledevice=0;}
if($_GET['mobile']==="false"){
$ismobiledevice=1;}
这意味着如果网址说mobile==false
,仍然转到移动版本。您可以简单地正确连接这两个 if 语句,如下所示:
if($detect->isMobile()&& $_GET['mobile']!="false"){
header("Location:http://m.he2media.com");
}else{
header("Location:http://www.he2media.com");
}