dongxiaoxiao1983 2013-10-08 17:52
浏览 62

了解缓存限制器| 标题已经发送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

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."

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

include 'db_connect.php';
include 'functions.php';

sec_session_start(); is a custom session start located in functions.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?

Edit: index_3.php (from line 1 through )

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
 <meta name="Generator" content="Xara HTML filter v."/>
 <meta name="XAR Files" content="index_htm_files/xr_files.txt"/>
 <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>

EDIT 2: somewhere inside index_3.php

<div style="width:  480px;  height:  175px;  overflow:  auto;">
<?php include 'get_opwire.php'; ?>
  • 写回答

2条回答 默认 最新

  • doudun8705 2013-10-08 17:58

    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.

    EDIT 1

    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

    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.

    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.

    EDIT 3: "No output" includes any and all HTML.

    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.

    EDIT 4

    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. Have separate files. You would have a file like page_start.php that does includes and session_start that you include at the very top of index_3.php, and a file like display_table.php that displays your table that you include where the table goes.
    2. Turn the table into a function. You would wrap the table output inside a function, include get_opwire.php at the very top of index_3.php, then call the function down where you want the table.
    3. Use output buffering. Output buffering catches the stuff printed out so that you can use it later. It would go like this:

    top of index_3.php:

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

    where the table goes:

     echo $table; 
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 我下载图形界面重启完就变成这样了,打字也打不了,动也动不了,该怎么解决(操作系统-centos)
  • ¥15 VBA中在窗体中遍历所有checkbox控件,提取出被选中的checkbox的caption值
  • ¥15 在Ubuntu上有什么命令,或者是系统文件能告诉我链接nvme ssd的pcie槽位是不是支持热插拔功能?
  • ¥15 ansys license许可证问题
  • ¥20 QQ号和密码都能正常登录微信 QQ号和密码登录微信显示密码错误
  • ¥15 qiankun主应用注册子应用提示跨域
  • ¥15 单片机RTOS Kernel与应用分离开发,Kernel如何调起应用?
  • ¥15 快手小店商家版APP怎么第三方APP跳转到指定用户聊天界面
  • ¥15 为什么AVL fire软件仿真时的步长改变了,仿真结果也会改变
  • ¥100 如何帮我写一个java小游戏