了解缓存限制器标头已发送php警告 [英] Understanding cache limiter | headers already sent php warning

查看:84
本文介绍了了解缓存限制器标头已发送php警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行良好的网站,但只是通过刷新主页(index_3.php),我的错误日志中显示了两个警告。

I have a site that is functioning fine, but just by refreshing the main page (index_3.php) my error log populates with two warnings.

[08-Oct-2013 11:36:09] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home2/mysite/public_html/mysubsite/index_3.php:7) in /home2/mysite/public_html/mysubsite/functions.php on line 12

[08-Oct-2013 11:36:09] PHP Warning:  session_regenerate_id() [<a href='function.session-regenerate-id'>function.session-regenerate-id</a>]: Cannot regenerate session id - headers already sent in /home2/mysite/public_html/mysubsite/functions.php on line 13

我已经进行了充分的研究,以了解在会话开始之前某些东西正在发送页面数据,但是我似乎无法根除原因。直接从本教程站点的创建PHP函数中获取functions.php。 http://www.wikihow.com/Create -a-Secure-Login-Script-in-PHP-and-MySQL

I have researched enough to understand that something is sending the page data before the session begins, but I can't seem to root out the cause. functions.php is taken right from this tutorial site under "Create PHP Functions." http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL

也在index_3.php上加载的是get_opwire.php,它只是放置了一个表。 get_opwire.php的开头看起来像:

Also loading on index_3.php is get_opwire.php which just places a table. The beginning of get_opwire.php looks like:

<?php
include 'db_connect.php';
include 'functions.php';
sec_session_start();

sec_session_start(); 是自定义会话开始位于functions.php中。

sec_session_start(); is a custom session start located in functions.php

当我尝试将sec_session的顺序重新排列到顶部或在表格中断处移动这些位置时。 Index_3.php只是主页,大部分都是html,其中包括提交表单和get_opwire.php

When I try to rearrange the order of the sec_session to the top or shift those around the table breaks. Index_3.php is just the main page, mostly html that has includes for a submit form and get_opwire.php

有人可以帮我指出问题吗?

Would someone be able to help point me to the problem?

编辑:index_3.php(从第1行到)

index_3.php (from line 1 through )

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
 <meta name="Generator" content="Xara HTML filter v.6.0.1.335"/>
 <meta name="XAR Files" content="index_htm_files/xr_files.txt"/>
 <title>index_3</title>
 <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
 <link rel="stylesheet" type="text/css" href="index_htm_files/xr_main.css"/>
 <link rel="stylesheet" type="text/css" href="index_htm_files/xr_text.css"/>
 <link rel="stylesheet" type="text/css" href="index_htm_files/custom_styles.css"/>
 <script type="text/javascript" src="index_htm_files/roe.js"></script>
 <!--[if IE]><script type="text/javascript" src="index_htm_files/prs.js"></script><![endif]--><!--[if !IE]>--><script type="text/javascript" src="index_htm_files/prs3.js"></script><!--<![endif]-->
 <script type="text/javascript">var xr_nextpage=""; var xr_transition=0; var xr_transitiontime=0;var xr_prevpage="index_2.htm"; var xr_btransition=0; var xr_btransitiontime=500;</script>
 <style type="text/css">.xr_pbd {position: absolute; border:none; left: 50%; margin-left: -380px;}</style>
</head>

编辑2:在index_3.php内的某处

<html>
<body>
<div style="width:  480px;  height:  175px;  overflow:  auto;">
<?php include 'get_opwire.php'; ?>
</div>
</body>
</html> 


推荐答案

会话启动和会话重新生成ID之前的某个地方页面上的内容。如果您确定没有在页面上回显或打印任何内容,则可能是其中一个文件顶部的空白。

Something somewhere before session start and session regenerate id is putting something on the page. If you are sure you're not echoing or printing anything to the page, it's probably a blank space at the top of one of the files.

编辑1

某些文本编辑器/文字处理程序会以看不见的形式保存文件字符位于顶部(由于编码)。尝试在纯文本编辑器或建议用于编码的文本编辑器(例如Notepad ++)中将文件的文本复制并粘贴到新文件中。

Some text editors/word processors save files with extra invisible characters at the top due to encoding. Try copying and pasting the text of the files into new files in a plain text editor or text editor recommended for coding, such as Notepad++.

EDIT 2

因此,那些是最可能的解决方案...。它说

So, those were the most likely solutions.... It says

output started at /home2/mysite/public_html/mysubsite/index_3.php:7

这意味着index_3.php的第7行开始输出。

which means that it's line 7 of index_3.php where the output starts at. There is probably a space there or maybe some kind of error that causes output to be sent.

如果确实找不到不可见的输出,则可以使用缓冲 ob_start 等捕获所有输出。在会话开始之前放置ob_start,稍后再使用ob_end_flush显示页面。但这并不是您不知道发送输出的事实的真正解决方法。

If you really can't find that invisible output, you can use buffering with ob_start etc. to catch all output. Put ob_start before your session start and use ob_end_flush later to display the page. But that's not a real fix for the fact that you're sending output without knowing it.

编辑3:无输出包括所有HTML。

如果任何文件中的某些内容不在PHP括号内<?php?>那么重要。您的index_3.php文件以HTML开头。那是输出。您必须先执行get_opwire.php。

If there's something in any file that is not inside PHP brackets <?php ?> then that counts. Your index_3.php file starts with HTML. That is output. You have to do get_opwire.php first.

编辑4

关于如何get_opwire.php同时具有页面开始的内容和表格的打印输出,这是为什么将显示代码与功能代码分开的一个好主意的示例。您有三个选择:

Concerning how get_opwire.php has both page-start stuff and the table printout, it's an example of why it's a good idea to separate your display code from your functionality code. You have three options:


  1. 具有单独的文件。您将在index_3.php的最顶部有一个包含page_start.php的文件,该文件确实包含和session_start,在该表的最顶部有一个诸如display_table.php的文件,该文件显示了您的表。

  2. 将表转换为函数。您可以将表输出包装在一个函数中,将get_opwire.php包含在index_3.php的最顶部,然后在需要该表的位置调用该函数。

  3. 使用输出缓冲。输出缓冲可以捕获打印出来的内容,以便以后使用。它会像这样:

index_3.php的顶部:

top of index_3.php:

 ob_start();
 include get_opwire.php;
 $table = ob_get_contents();
 ob_end_clean();

表所在的位置:

 echo $table; 

这篇关于了解缓存限制器标头已发送php警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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