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." http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL

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(); 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" "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>

EDIT 2: somewhere inside index_3.php

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

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:

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

    where the table goes:

     echo $table; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮