|
Posted by J.O. Aho on 12/22/06 10:50
Dave Nash wrote:
> I now get this error message.
> Warning: session_start() [function.session-start]: Cannot send session
> cache limiter - headers already sent (output started at
> F:\webserver\2006_11_November\myprofile\includes\global.php:5) in
> F:\webserver\2006_11_November\myprofile\includes\auth.php on line 6
session, cookie and header must ALWAYS be sent before any output, so here are
some example on what you shouldn't do:
--- example: echo before session start ---
<?php
echo "Hello";
session_start();
?>
--- eof ---
--- example: whitespace before php-tag ---
<?PHP
session_start();
?>
--- eof ---
When including files, the whitespace before AND after php-tag will cause you
troubles even if your main file is correct.
There are two things you can do
1 - store all output into a variable say $output, and when all headers,
cookies, sessions are sent and all the output has been stored to the variable,
first then do a: echo $output;
2 - use output buffer, you must use ob_start() before any output that is
generated by php, you still have to be careful with whitespaces and other
output outside the php-tag. http://se.php.net/manual/en/function.ob-start.php
Both methods works, using the first method can give a more clean code, as it
will require a little bit more thinking.
--
//Aho
[Back to original message]
|