Page 1 of 1

Warning: Cannot modify header information...

Posted: Thu Feb 19, 2004 1:46 pm
by ReneGade
ok here is the error in full:

Warning: Cannot modify header information - headers already sent by (output started at /getcookie.php:4) in /getcookie.php on line 46

I have been Searching for days on solutions that may fix this problem and people always lead back to the header, see the funny part is that im not touching the header, i think the problem maybe that im trying to use a second cookie and i am also using sessions, im using phpbb and i am making a second login for my main site so that they are integrated, the error always occurs when the script trys to set the cookie. here is the actual code, any help would be greatly appreciated.

if (($username == $user) && ($p == "3")) {
$check = "1";
echo "Full Access";
setcookie ("admin","admin1");
}

To help you all understand my coding $username is the name they entered into the login field and $user is the username set inside the database, $p is the permission level.

Posted: Thu Feb 19, 2004 2:25 pm
by pickle
The only time I've had this problem is when I'm echoing something before I change the headers. So, for example, if I have

Code: Select all

echo "test";
header("Location: somewhere.else");
I'll get that error.

What is being done on line 46? Is there output? One final thought is that session_start() needs to be the first thing done on any page using sessions. Anything before it will break. That may be your problem.

Thx for your help.

Posted: Thu Feb 19, 2004 4:55 pm
by ReneGade
Yeah it was a series of things that was causeing the error, first off was the session thing at the top of the page ( i didnt have it) second was i was echoing a command before i was setting the cookie. Thanks for all your help.

Posted: Thu Feb 19, 2004 5:07 pm
by pickle
FYI: I'm not certain that echoing stuff before setting a cookie will give you that error. Setting cookies has nothing to do with headers, so the problem was probably only with the session thing.