php - header 位置已发送

标签 php error-handling header

很抱歉再次提出这个常见问题,但我找不到答案。
所以我在我的menu.php中得到了这个错误,即时消息包括在我的索引中:

"Cannot modify header information - headers already sent by (output started at /home/andxeavr/public_html/bulfit.com/benching/index.php:61) in /home/andxeavr/public_html/bulfit.com/benching/includes/menu.php on line 20"

这是我的索引行61:
include('includes/menu.php');

这是我的menu.php:
if (isset($_POST['search_sub'])) {

header("Location: sign_up.php");

}

所以我尝试使用ob_start()和其他喜欢的答案,但是没有用。

最佳答案

这个问题已经被回答了太多次了:

How to fix "Headers already sent" error in PHP

但仍然:您可以尝试通过在文件顶部使用来避免标题位置已发送错误:

ob_start();

但也请尝试查看您的代码,看看是否没有多余的空间,并且在从文件开始启动php的开始标记之前没有任何空间。 :
<?php
  header("Location: /");
?>

还要查看menu.php文件内部,您之前没有任何空间
   <?php

然后做
<?php

关于php - header 位置已发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30909112/

相关文章:

python - 在Django中使用limit和order_by进行数据库查询

javascript - 试图映射到React

php - 如何从客户端使浏览器缓存中的页面无效?

PHP 查询向表中插入 2 行

php - TCPDF 错误 : Can't open image file:/var/www/html/tcpdf/cache/

asp.net-mvc-4 - ASP.NET MVC中的自定义页错误500

c++ - 如何在arduino库头中覆盖#define

header 后 PHP session 被销毁/丢失

php - 在 Twig 中获取数组键? (交响乐)

php - Laravel 资源路由被分配了错误的参数名称