By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Warning:Cannot modify header information...

P: n/a
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 <?php
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.)

<?php
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

Sep 4 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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 <?php
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.)

<?php
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 <?php if you save as UTF8)
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.

Sep 4 '07 #2

P: n/a
Joe
<mc******@yahoo.comwrote in message
news:11**********************@w3g2000hsg.googlegro ups.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 <?php
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.)

<?php
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 <?php
)

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

<?php
if(headers_sent($file, $line)){
echo "Headers already sent in $file on line $line";
}
?>
Sep 4 '07 #3

P: n/a
mc******@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 <?php
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.)

<?php
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.
js*******@attglobal.net
==================
Sep 4 '07 #4

P: n/a
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
Sep 4 '07 #5

P: n/a
mc******@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.)

<?php
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.
Sep 4 '07 #6

P: n/a
On Tue, 04 Sep 2007 22:12:37 +0200, shimmyshack <ma********@gmail.com>
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 <?php
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.)

<?php
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
Sep 4 '07 #7

P: n/a
On Tue, 04 Sep 2007 22:53:16 +0200, <mc******@yahoo.comwrote:
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
Sep 4 '07 #8

P: n/a
On Sep 4, 7:26 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
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:

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

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

<?php
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:

<?php
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

Sep 5 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.