PHP - Bits & Pieces

PHP programming codes and scripting are discussed in the manner of use and relevance. Examples of PHP syntax and scripting are presented in concise writups for better understanding.

Wednesday, May 28, 2008

Using PHP to solve the session_start() Error

This is a commonly occurred error in PHP programming. It is usually caused by the session start script. When a separate header file is included at the top of the page, the error is caused by duplicate HTML tag or white space before the session start script. This happen when the web page try to resend headers information

Error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent


Solution:

Place the following script at the top of the page:
<?php
ob_start();
session_start();
?>


and this at the end of the page:
<?php // Flush the buffered output to the Web browser.
ob_flush();
?>

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home