PHP修正警告:不能修改标题信息 - 已经发送的标题 [英] PHP Fix Warning: Cannot modify header information - headers already sent

查看:118
本文介绍了PHP修正警告:不能修改标题信息 - 已经发送的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

警告:无法修改标题信息 - 已在/home/blocexco/public_html/public_html/classes/mysql/mysql.security.php在线发送的标题(输出开始于/home/blocexco/public_html/homepage.php:73) 99



第100行的mysql.security.php第二次重复该错误。



homepage: 73

 < div class =login> 
<?php require_once'login.php'; ?>
< / div>

mysql.security.php:99-100

  setcookie('username',,time() - (60 * 60 * 24 * 365)); 
setcookie('password',,time() - (60 * 60 * 24 * 365));

我知道这不是一个BOM问题,因为我已经读过。在我调用header()和setcookie()函数之前和之后都有输出 - 这是必要的,因为主页包含一个php文件,然后注入正确的登录或注销表单。



我听说过在内容开始处使用ob_start(),但这不是一个非常具体的指令......我试着将它放在homepage.php的开头(就在html标签之前)修理任何东西。

我是PHP的新手(几天之内,并且一般来说是新手)。说实话,它让我发现我不能只是改变我所在的页面,或者通过PHP创建cookie,而不用向后弯曲......

class解决方案方案

好了,在输出开始之后,你不能输出任何头文件,包括cookies。期间。

这是一个简单的技术限制,因为HTTP标头需要在HTTP主体之前发送。这不是PHP在这里的错误。



您应该以一种首先决定应该发送什么并收集所有必要信息的方式来构建应用程序数据,然后继续输出实际的HTML。在主HTML体内混合逻辑很麻烦,但是你看它。例如,查看MVC模式。


Warning: Cannot modify header information - headers already sent by (output started at /home/blocexco/public_html/homepage.php:73) in /home/blocexco/public_html/classes/mysql/mysql.security.php on line 99

This error is repeated a second time for mysql.security.php on line 100.

homepage:73

<div class="login">
<?php require_once 'login.php'; ?>
</div>

mysql.security.php: 99-100

      setcookie('username', "", time() - (60 * 60 * 24 * 365));
      setcookie('password', "", time() - (60 * 60 * 24 * 365));

I know this isn't a "BOM" issue as I've read about. There is output before and after my calls to header() and setcookie() functions - this is necessary since the homepage includes a php file which then injects the right login or logout form.

I've heard about using ob_start() at the beginning of content, but that's not a very specific instruction...I tried placing it at the beginning of homepage.php (just before the html tag) and that didn't fix anything.

I'm new to PHP (a few days in, and new to web-app dev in general). To be honest, it blows my mind that I can't just change which page I am on or create cookies, via php without bending over backwards...

解决方案

Well, you can't output any headers, including cookies, after output was started. Period.
It's a simple technical restriction, since HTTP headers need to be sent before the HTTP body. It's not PHP that's at fault here.

You should structure your app in a way that first decides what should be sent and gathers all the necessary data, then proceeds to output the actual HTML. Mixing logic inside the main HTML body is messy however you look at it. Look into the MVC pattern for example.

这篇关于PHP修正警告:不能修改标题信息 - 已经发送的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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