Warning: Cannot modify header information ERROR

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
kelvingeorge
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 3:57 pm

Warning: Cannot modify header information ERROR

Post by kelvingeorge »

Hi there.. I get this error

Warning: Cannot modify header information - headers already sent by

The code works fine in the main folder.. But the same code in the /admin folder it does not work.. :banghead: It gives the above error... So I put all pages in same main folder without any sub-folders.. Then when session expires this error comes again.. I go back and re-login same page works fine.. Can anyone help me with this??
Some where I read the error was due to UTF-8(w/BOM) encoding... I fixed that part, but still i get same warning.. Help :?
kishanprasad
Forum Newbie
Posts: 16
Joined: Mon Feb 25, 2008 5:20 pm

Re: Warning: Cannot modify header information ERROR

Post by kishanprasad »

try to check some where in your program you have echoed some thing before the header ....

may be the echo is coming when the session expires...


i think generally "the headres already sent" will cm due to the echoes ...
kelvingeorge
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 3:57 pm

Re: Warning: Cannot modify header information ERROR

Post by kelvingeorge »

Code: Select all

$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
 
//then redirect them to the members area
header("Location: member.php");
Thats the code... I get error for last three lines

Warning: Cannot modify header information - headers already sent by (output started at.................................. C:\project\websites\bb\check.php line 62
Warning: Cannot modify header information - headers already sent by (output started at.................................. C:\project\websites\bb\check.php line 63
Warning: Cannot modify header information - headers already sent by (output started at.................................. C:\project\websites\bb\check.php line 66
kishanprasad
Forum Newbie
Posts: 16
Joined: Mon Feb 25, 2008 5:20 pm

Re: Warning: Cannot modify header information ERROR

Post by kishanprasad »

as it showing the line nos as 62,63,66 can you tell me which line nos is it referring to is it the code that yous en to me or any other

(or)


try to put a ob_start() on the first line itself and ob_endflush() on the last to avoid thhis
kelvingeorge
Forum Newbie
Posts: 7
Joined: Fri Feb 22, 2008 3:57 pm

Re: Warning: Cannot modify header information ERROR

Post by kelvingeorge »

Code: Select all

62 setcookie(ID_my_site, $_POST['username'], $hour);
63 setcookie(Key_my_site, $_POST['pass'], $hour);
64  
65 //then redirect them to the members area
66 header("Location: member.php");
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Warning: Cannot modify header information ERROR

Post by JAB Creations »

With my PHP templating system I keep my headers and non-header includes organized so I never encounter this error...

header.php
header-01-this.php
header-02-that.php
header-03-peanut-butter.php
header-04-jelly.php
includes-00-template-01-head.php
includes-00-template-02-body.php
includes-00-template-03-foot.php
includes-01-xml.php
includes-02-doctype.php
includes-03-css.php
includes-04-js.php
Post Reply