Warning: Cannot modify header information...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ReneGade
Forum Newbie
Posts: 2
Joined: Thu Feb 19, 2004 1:46 pm

Warning: Cannot modify header information...

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ReneGade
Forum Newbie
Posts: 2
Joined: Thu Feb 19, 2004 1:46 pm

Thx for your help.

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply