下面的代码显示我“111
”和“222
”。但不会将我重定向到任何地方。我现在能做什么?重定向和标题不起作用
<?php
echo "111";
header("Location: http://www.google.com");
echo "222";
return Redirect::to('http://www.google.com');
echo "333";
?>
下面的代码显示我“111
”和“222
”。但不会将我重定向到任何地方。我现在能做什么?重定向和标题不起作用
<?php
echo "111";
header("Location: http://www.google.com");
echo "222";
return Redirect::to('http://www.google.com');
echo "333";
?>
你不能有标题标签设置之前任何输出,所以头后删除echo语句,并退出脚本:
header("Location: http://www.google.com");
exit;
谢谢,但仍然没有任何反应 – divHelper11
你发布脚本的完整脚本? – Ashley
两件事情......
你需要把你的exit
头之后( “位置:...”) 例子:
header("Location: http://www.google.com");
exit;
但更重要的是,如果您已使用echo
写入输出缓冲区,您的标题将不会重定向。
谢谢,但仍然没有任何反应 – divHelper11
请注意,在使用header()之前,您不能有任何输出。所以没有回声,var_dump,没有或任何以上的PHP标记,没有包括标题,什么都没有。 – Ivar
这不起作用,因为您已经将数据发送到客户端(echo
)。要么把你的头,你什么呼应前,或缓冲这样的:
ob_start();
echo "111"; //Note: You're missing a semicolon here
header("Location: http://www.google.com");
echo "222";
$obj = Redirect::to('http://www.google.com');
echo "333";
ob_flush();
return $obj;
To Continue Reading... 希望这有助于!
return语句将跳出这一点,ob_flush()将永远不会到达 – bashaus
http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php检查此链接 –
可能重复[如何解决“头已发送”错误PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Epodax
使用ob_start();在你的代码的开头 – 2015-11-02 14:17:19