开发者

Cannot modify header information - PHP [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

PHP error: Cannot modify header information – headers already sent

I have built a website with lots of functions supported by programming. As the website is growing bigger, I found when doing photo upload, login, the following errors appear:-

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in /var/www/web92/web/li/sli.php on line 63

Warning: Cannot modify header information - h开发者_开发知识库eaders already sent by (output started at /var/www/web92/web/index826.php:62) in /var/www/web92/web/li/sli.php on line 72

I found adding ob_start(); at the very beginning of index can solve the problem, however, I would like to learn, if the running of php codes may have length limit.


please ensure that

session_start() is called before outputing anything to the browser

refer notes in http://php.net/manual/en/function.session-start.php


session_start() should be called before any output to the page.

Incorrect

<?php
$calculation = 1 + 1;

echo $calculation;

session_start();
?>

Correct

<?php
$calculation = 1 + 1;

session_start();

echo $calculation;
?>

Notice that you can still run code before, but ensure it does not output anything to the browser before calling the session_start() function.


The message

output started at /var/www/web92/web/index826.php:62

means that you have already written out content and the server has begun streaming the response to the client. You cannot modify the headers because they have already been sent.

Move the header-generating code to a point before the very first output is written.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜