PHP header redirect not working(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 标头重定向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 标头重定向不起作用


基础教程推荐
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01