php Warning: Cannot modify header information

krahny

New Member
Messages
25
Reaction score
0
Points
0
Hey, I have this code in php:

setcookie("remember",$_POST[username],$expire);

This keeps appearing on the page:

Warning: Cannot modify header information - headers already sent by (output started at /home/krahny/public_html/login.php:16) in /home/krahny/public_html/login.php on line

I cant figure out whats wrong. Could someone help me?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Try searching the forums. This issue has been covered many times before. Usually header() is involved, but setcookie() is just a specialized call to header().

Make sure you understand how HTTP works. You can no more set a header once you start sending content than dial a different number while you are talking to someone on the phone (HTTP has no conference calls).
 

matthew88

New Member
Messages
9
Reaction score
1
Points
0
using cookies is rough. However this header problem your running into due to the location of where the header is located

So setting cookies must happen before the actual header which looks like below. So you must set cookies before that code section. Good luck and i hope that answered ur question. PS setting multi header things with sessions or possible cookies could create a similar error.

<html>

<head>

<title></title>

</head>

<body>

</body>

</html>
 
Top