Warning:Cannot modify header information...

Warning:Cannot modify header information...

am 04.09.2007 21:44:29 von mcserret

I know this is a recurring problem that has been addressed here
before, but even after reading all that has gone before, I am still
stumped.

I have a form that is designed to send data to a PHP page where is is
to be validated then read into a MySQL table. Once that is done, the
form is to send the user either back to the originating page, or to a
logout page.

I have several versions of this setup on my site that work well, so
why should it not work on one page?

I have checked for blanks and extra characters before and after and ?> tags. there are none.

I have POSTed to a page with _only_ the following code: (Again- there
are no blanks or other characters either before or after.)

header("location:www.foo.org/subdir/enterStuff.php");
?>

It still comes back with:
"Warning: Cannot modify header information - headers already sent by
(output started at /var/www/foo.org/html/subdir/postStuff.php:1) in /
var/www/foo.org/html/Events/postStuff.php on line 2."

I have stripped the code (a combination of php and javascript) in the
orginating file of all extraneous stuff. Still not getting anywhere.
I tried adding ob_start() and ob_end_flush() , still no joy.

If I leave out the "header()" and "exit()" lines, the page processes
and stores the information correctly and without any reported errors.

I think that covers all the advise I've seen here, so my question is:
Does anyone know what else can cause this problem?

MC

Re: Warning:Cannot modify header information...

am 04.09.2007 22:12:06 von joe

wrote in message
news:1188935069.269968.221990@w3g2000hsg.googlegroups.com...
>I know this is a recurring problem that has been addressed here
> before, but even after reading all that has gone before, I am still
> stumped.
>
> I have a form that is designed to send data to a PHP page where is is
> to be validated then read into a MySQL table. Once that is done, the
> form is to send the user either back to the originating page, or to a
> logout page.
>
> I have several versions of this setup on my site that work well, so
> why should it not work on one page?
>
> I have checked for blanks and extra characters before and after > and ?> tags. there are none.
>
> I have POSTed to a page with _only_ the following code: (Again- there
> are no blanks or other characters either before or after.)
>
> > header("location:www.foo.org/subdir/enterStuff.php");
> ?>
>
> It still comes back with:
> "Warning: Cannot modify header information - headers already sent by
> (output started at /var/www/foo.org/html/subdir/postStuff.php:1) in /
> var/www/foo.org/html/Events/postStuff.php on line 2."
>
> I have stripped the code (a combination of php and javascript) in the
> orginating file of all extraneous stuff. Still not getting anywhere.
> I tried adding ob_start() and ob_end_flush() , still no joy.
>
> If I leave out the "header()" and "exit()" lines, the page processes
> and stores the information correctly and without any reported errors.
>
> I think that covers all the advise I've seen here, so my question is:
> Does anyone know what else can cause this problem?


Are you sure there is nothing at the top of the page (before your )

If so, try this on the very top line. (no blank lines or spaces)

if(headers_sent($file, $line)){
echo "Headers already sent in $file on line $line";
}
?>

Re: Warning:Cannot modify header information...

am 04.09.2007 22:12:37 von shimmyshack

On Sep 4, 8:44 pm, mcser...@yahoo.com wrote:
> I know this is a recurring problem that has been addressed here
> before, but even after reading all that has gone before, I am still
> stumped.
>
> I have a form that is designed to send data to a PHP page where is is
> to be validated then read into a MySQL table. Once that is done, the
> form is to send the user either back to the originating page, or to a
> logout page.
>
> I have several versions of this setup on my site that work well, so
> why should it not work on one page?
>
> I have checked for blanks and extra characters before and after > and ?> tags. there are none.
>
> I have POSTed to a page with _only_ the following code: (Again- there
> are no blanks or other characters either before or after.)
>
> > header("location:www.foo.org/subdir/enterStuff.php");
> ?>
>
> It still comes back with:
> "Warning: Cannot modify header information - headers already sent by
> (output started at /var/www/foo.org/html/subdir/postStuff.php:1) in /
> var/www/foo.org/html/Events/postStuff.php on line 2."
>
> I have stripped the code (a combination of php and javascript) in the
> orginating file of all extraneous stuff. Still not getting anywhere.
> I tried adding ob_start() and ob_end_flush() , still no joy.
>
> If I leave out the "header()" and "exit()" lines, the page processes
> and stores the information correctly and without any reported errors.
>
> I think that covers all the advise I've seen here, so my question is:
> Does anyone know what else can cause this problem?
>
> MC

you could have autoprepend on, set to prepend a file with response
body content in it.
you could be using a free host which prepends a file
you could have saved the php file with BOM mark (which some editors
save before the there is definately body content being returned I suggest using a
proxy to see what exactly and go from there. download fiddlertool for
windows i assume youre on windows.

Re: Warning:Cannot modify header information...

am 04.09.2007 22:20:31 von Jerry Stuckle

mcserret@yahoo.com wrote:
> I know this is a recurring problem that has been addressed here
> before, but even after reading all that has gone before, I am still
> stumped.
>
> I have a form that is designed to send data to a PHP page where is is
> to be validated then read into a MySQL table. Once that is done, the
> form is to send the user either back to the originating page, or to a
> logout page.
>
> I have several versions of this setup on my site that work well, so
> why should it not work on one page?
>
> I have checked for blanks and extra characters before and after > and ?> tags. there are none.
>
> I have POSTed to a page with _only_ the following code: (Again- there
> are no blanks or other characters either before or after.)
>
> > header("location:www.foo.org/subdir/enterStuff.php");
> ?>
>
> It still comes back with:
> "Warning: Cannot modify header information - headers already sent by
> (output started at /var/www/foo.org/html/subdir/postStuff.php:1) in /
> var/www/foo.org/html/Events/postStuff.php on line 2."
>
> I have stripped the code (a combination of php and javascript) in the
> orginating file of all extraneous stuff. Still not getting anywhere.
> I tried adding ob_start() and ob_end_flush() , still no joy.
>
> If I leave out the "header()" and "exit()" lines, the page processes
> and stores the information correctly and without any reported errors.
>
> I think that covers all the advise I've seen here, so my question is:
> Does anyone know what else can cause this problem?
>
> MC
>

Are you by any chance using an editor which is utf-8 aware?

What happens if you open this file in notepad (Windows) or vim (Linux)?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Warning:Cannot modify header information...

am 04.09.2007 22:53:16 von mcserret

On Sep 4, 3:44 pm, mcser...@yahoo.com wrote:
> I know this is a recurring problem that has been addressed here
> before, but even after reading all that has gone before, I am still
> stumped.


OK- here's a followup, and it STILL does not make any sense!

This part of the site is to be secured by a login, so both files would
eventually be headed by "session_start()".

Just for the hell of it, I stuck session_start() at the head of
processStuff.php (the file that was gving me all the errors) along
with code that redirects (via header()... exit() ) to the login page
or back to the originating page if it was a valid SESSION.

And waddya know! At first run, I was not logged in, so it sent me
(via the cursed header() instruction!) to my login page!!!

So I dutifully logged in and went to the cursed page and..... damn
thing works!!!!

Now- why, when I was debugging and did not _want_ any of the SESSION
stuff in the code, did it stubbornly return all those $#$&*#!
Warnings? Other than the "session_start()", it was the Same Damn
Code!

I need another cup of coffee!

Just to answer one question, this originally was done in Dreamweaver,
but I switched to Notepad after an hour of frustration.

MC

Re: Warning:Cannot modify header information...

am 04.09.2007 23:10:00 von Bucky Kaufman

mcserret@yahoo.com wrote:

> I have POSTed to a page with _only_ the following code: (Again- there
> are no blanks or other characters either before or after.)
>
> > header("location:www.foo.org/subdir/enterStuff.php");
> ?>
>
> It still comes back with:
> "Warning: Cannot modify header information - headers already sent by
> (output started at /var/www/foo.org/html/subdir/postStuff.php:1) in /
> var/www/foo.org/html/Events/postStuff.php on line 2."

I'm not always sure *why*, but putting session_start() at the top has
always resolved that problem for me.

Apparently, if you don't, the web server tends to start sending headers
even before the page runs.

I'm not sure how that is possible - because it seems that the web server
would have to predict when a page uses session_start() or not.

But... it fixes the problem... for me.

Re: Warning:Cannot modify header information...

am 05.09.2007 01:23:22 von luiheidsgoeroe

On Tue, 04 Sep 2007 22:12:37 +0200, shimmyshack
wrote:

> On Sep 4, 8:44 pm, mcser...@yahoo.com wrote:
>> I know this is a recurring problem that has been addressed here
>> before, but even after reading all that has gone before, I am still
>> stumped.
>>
>> I have a form that is designed to send data to a PHP page where is is
>> to be validated then read into a MySQL table. Once that is done, the
>> form is to send the user either back to the originating page, or to a
>> logout page.
>>
>> I have several versions of this setup on my site that work well, so
>> why should it not work on one page?
>>
>> I have checked for blanks and extra characters before and after >> and ?> tags. there are none.
>>
>> I have POSTed to a page with _only_ the following code: (Again- there
>> are no blanks or other characters either before or after.)
>>
>> >> header("location:www.foo.org/subdir/enterStuff.php");
>> ?>
>>
>> It still comes back with:
>> "Warning: Cannot modify header information - headers already sent by
>> (output started at /var/www/foo.org/html/subdir/postStuff.php:1) in /
>> var/www/foo.org/html/Events/postStuff.php on line 2."
>>
>> I have stripped the code (a combination of php and javascript) in the
>> orginating file of all extraneous stuff. Still not getting anywhere.
>> I tried adding ob_start() and ob_end_flush() , still no joy.
>>
>> If I leave out the "header()" and "exit()" lines, the page processes
>> and stores the information correctly and without any reported errors.
>>
>> I think that covers all the advise I've seen here, so my question is:
>> Does anyone know what else can cause this problem?
>>
>> MC
>
> you could have autoprepend on, set to prepend a file with response
> body content in it.

I'm not sure, but wouldn't the error say it was started on line 0 for
internal reasons?
--
Rik Wasmus

Re: Warning:Cannot modify header information...

am 05.09.2007 01:26:01 von luiheidsgoeroe

On Tue, 04 Sep 2007 22:53:16 +0200, wrote:

> On Sep 4, 3:44 pm, mcser...@yahoo.com wrote:
>> I know this is a recurring problem that has been addressed here
>> before, but even after reading all that has gone before, I am still
>> stumped.
>
>
> OK- here's a followup, and it STILL does not make any sense!
>
> This part of the site is to be secured by a login, so both files would
> eventually be headed by "session_start()".
>
> Just for the hell of it, I stuck session_start() at the head of
> processStuff.php (the file that was gving me all the errors) along
> with code that redirects (via header()... exit() ) to the login page
> or back to the originating page if it was a valid SESSION.
>
> And waddya know! At first run, I was not logged in, so it sent me
> (via the cursed header() instruction!) to my login page!!!
>
> So I dutifully logged in and went to the cursed page and..... damn
> thing works!!!!
>
> Now- why, when I was debugging and did not _want_ any of the SESSION
> stuff in the code, did it stubbornly return all those $#$&*#!
> Warnings? Other than the "session_start()", it was the Same Damn
> Code!
>
> I need another cup of coffee!
>
> Just to answer one question, this originally was done in Dreamweaver,
> but I switched to Notepad after an hour of frustration.

Well, it's obvious some kind of output was created, and relocating it the
starting of the session placed it before the code that did the output.
Without the original script there's not much I can say about where or why
though... (hint).
--
Rik Wasmus

Re: Warning:Cannot modify header information...

am 05.09.2007 17:56:01 von mcserret

On Sep 4, 7:26 pm, "Rik Wasmus" wrote:

> Well, it's obvious some kind of output was created, and relocating it the
> starting of the session placed it before the code that did the output.
> Without the original script there's not much I can say about where or why
> though... (hint).
> --

Rick-

I gave a short, but complete example of the code that failed in my
original post. It was:

header("location:www.foo.org/subdir/enterStuff.php");
?>

Here is the code that _worked_, after I included the SESSION variables
at the top.

session_start();

if(session_is_registered("SESSION")){
$issession=1;
header("location:www.foo.com/enterStuff.php"); //logged in
}
else {
header("location:www.foo.com/login/index.php"); //not logged in
exit();
}

$x7 = $_POST['rAction'];
$x0 = $_POST['year'];
$x1 = $_POST['month'];
$x2 = $_POST['day'];
$x3 = $_POST['event'];
$x4 = $_POST['desc'];
$x5 = $_POST['emph'];
$x6 = $_POST['canc'];

//format date for database
$x1 = $x1 + 1;
$dt = $x0 . "-" . $x1 . "-" . $x2;

$user = "user";
$password = "pass";
$database = "db";
$dbh = @mysql_connect ("localhost", $user, $password);
@mysql_select_db($database);

if($x7 == 3) {
$fId = $_POST[frmId];
$qry = "UPDATE `schedule` SET `date`='$dt', `event`='$x3',
`descript`='$x4', `emph`='$x5', `canc`='$x6', `modby`='$m' WHERE `id`
= $fId LIMIT 1";
@mysql_query($qry) or die ("Query failed: " . mysql_error());

} else {

$qry = "INSERT INTO `schedule`
(`date`,`event`,`descript`,`emph`,`canc`,`modby`) VALUES
('$dt','$x3','$x4','$x5','$x6','$m')";
@mysql_query($qry) or die ("Query failed: " . mysql_error());
}

mysql_close($dbh);

exit();
?>

Now if I _remove_ the SESSION section, so that it starts like this:

header("location:www.foo.com/enterStuff.php");

$x7 = $_POST['rAction'];
$x0 = $_POST['year'];
$x1 = $_POST['month'];
.....

exit();
?>

the dreaded "Warning:..." pops up. Note that the data will still get
processed, but the user will not be returned.

MC