PHP 标头重定向不起作用 [英] PHP header redirect not working

查看:39
本文介绍了PHP 标头重定向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道之前已经讨论过这个问题,但我找不到答案,

I know this has been covered before but I cannot find an answer to this,

我一直用这个;

header("Location: http://www.website.com/");
exit();

这在我当前的项目中一直有效,突然间它在我的任何浏览器中都不起作用

This has always worked in my current project and all of a sudden it is not working in any of my browsers

我想找出问题并解决它,而不是使用

I would like to figure out the problem and fix it instead of using

echo "<script type='text/javascript'>window.top.location='http://website.com/';</script>";

我也启用了错误报告,但没有显示任何错误

I also have error reporting enabled and it shows no errors

// SET ERROR REPORTING
error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);
ini_set('display_errors', TRUE);

知道为什么它不起作用吗?

推荐答案

尝试:

error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);


flush();
header("Location: http://www.website.com/");
die('should have redirected by now');

看看你得到了什么.你不应该在你的 error_reporting() 调用中使用 ^ (xor) 因为你无意中要求所有错误,除了通知和警告..这就是标题已经发送"错误.

See what you get. You shouldn't use ^ (xor) in your error_reporting() call because you're unintentionally asking for all errors EXCEPT notices and warnings.. which is what a 'headers already sent' error is.

还可以尝试将 flush() 放在 header() 调用的正上方.

Also try putting flush() right above your header() call.

这篇关于PHP 标头重定向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆