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 标头重定向不起作用


基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php中的PDF导出 2022-01-01