Ban*_*njo 2 php redirect header
我的主页上有一个简单的重定向,它对智能手机或平板电脑上的用户做出反应.该类正在工作,并在智能手机上打开侧面时返回true.
因此,如果我在if语句中写回声,它就会被回显.但重定向不起作用,我无法理解它.任何人都知道我错过了什么?
include ('includes/Mobiledetecter.php');
$detect = new Mobiledetecter;
//
if($detect->isMobile() or $detect->isTablet()) {
header('Location: http://www.example.com/');
}
Run Code Online (Sandbox Code Playgroud)
如果没有别的办法,请在设置标题后立即退出:
if($detect->isMobile() or $detect->isTablet()) {
header('Location: http://www.example.com/');
exit;
}
Run Code Online (Sandbox Code Playgroud)
还要考虑只有在您尚未将输出显式(例如:) echo或隐式地(例如:通过在包含此标头的标记之前包含空格的任何内容)向浏览器发送输出时,标头才有效<?php