Forum Moderators: coopster
Can anyone see why this would cause the errors (i've taken out the full URL btw in the error statement):
Warning: Cannot send session cookie - headers already sent by (output started at /***URL***.php:1) in /***URL***.php on line 2
Warning: Cannot send session cache limiter - headers already sent (output started at /***URL***.php:1) in /***URL***.php on line 2
Warning: Cannot add header information - headers already sent by (output started at /***URL***.php:1) in /***URL***.php on line 3
Heres the code... point out the dumb mistake I made! :) as i guess its something really obvious that I can't see...
<?
session_start();
header("Cache-control: private");
if (!$username) { $username = $_SESSION['username']; }
else { $username = $_POST['username']; }
$_SESSION['username'] = $username;
?>
[edited by: ergophobe at 6:07 pm (utc) on Sep. 29, 2005]
[edit reason] no need to include code downstream of error [/edit]
the actual error it turns out is that after looking into it more session_start() will always return true as default. SO if I call it on a page and it has no value, or give it a value without loading the page it will cause an error. Since I wanted it to store a variable from a form on that page and begin the session with no value, on securer servers - those with register_globals off, the session will of course error!
Since there is nothing insecure about it, I can simply use @session_start(); to tell it to ignore the error/ lack of value.
Now that probably made no sense, but it works.. :) Course when I have time, I will look into a better fix.
You can't just suppress the error with @ and expect the session to work. The error is telling you that the headers have already been sent, so it's too late to set a cookie (which is what you are doing, among other things, when starting a session).
You need to figure out where your output is coming from and stop it, or use output buffering.