开发者

PHP Session Warnings: what to do [duplicate]

This question already has answers here: 开发者_如何学Go How to fix "Headers already sent" error in PHP (11 answers) Closed 9 years ago.
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/moonpk/public_html/wallz/preview.php:16) in /home/moonpk/public_html/wallz/loginbox.php on line 2

 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/moonpk/public_html/wallz/preview.php:16) in /home/moonpk/public_html/wallz/loginbox.php on line 2

i am getting these two warning which i was not getting on local server... why ....


See the first note on the php session_start() page. session_start() sends cookies to the browser, and the server will not send any additional data (including cookies) after any data has already been sent. This can simply be fixed by making sure that nothing is being sent to the browser (such as an echo() or var_dump() call) before calling session_start().


You don't get them on local server because you have lower errer reporting level on it. So, you need:

  1. On you local server edit php.ini and set error_reporting to E_ALL
  2. Move you session_start() call before line 16 of you /home/moonpk/public_html/wallz/preview.php file


Most likely you have some whitespace outside any PHP-tags in files that are loaded before the session_start() is executed. Maybe your FTP client messed things up?


You probably had warnings suppressed on your local server? The issue is that you have some output before you call session_start. Judging by the line numbers, I'd guess you have a line break before your opening php tag, but without seeing the code, can't provide a full solution.


If you are including the page "preview.php" within "loginbox.php" check that you have only called session_start once on one page.

Either on preview.php or loginbox.php , not both.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜