473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Warning:Cannot modify header information...

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
8 2373
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phyzlo | last post by:
Hello, I've recently started learning PHP and have a question. I tried running below script which can be found at http://se2.php.net/manual/sv/function.setcookie.php but I keep getting this...
3
by: Greg Scharlemann | last post by:
Does the redirect statement: header(Location:"http://www.newpage.com"); need to come before certain statements? I've setup a login page and try to redirect a user once they have logged in...
4
by: kempy535 | last post by:
Hi I get this error code when I try to run my login script. Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\Rising...
5
by: nasse | last post by:
I am getting the following error msg whenever I try to login. I tried to turn my output_buffering = On in my php.ini but is not working for me. Would you please help me: Warning: Cannot modify...
2
by: mmr315 | last post by:
after installing php when i run php.exe it is showing that PHP Warning: Cannot load module 'pdo_mysql' because required module 'pdo' is not loaded in Unknown on line 0 what is this error,pls...
2
by: smartic | last post by:
I'm having problem with header redirection that is my code: <?php header("location:Redirecting.php"); exit; ?> //Then the HTML It give me an error
0
by: Georg | last post by:
Hello, I'm using SSIS (SQL Server Integration Services) via Native Informix OLE DB provider to extract (ETL) data from Informix 7.3 to SQL Server 2005. I have following problem, when I try...
3
by: gubbachchi | last post by:
Hi, I have written php code to retrive the image from mysql and display it on the webpage. Here is the code <?php require_once("DBConnect.php"); $gotten = @mysql_query("select user_photo from...
10
by: jessica87 | last post by:
hi there, i m using this coding to retrieve the file from database so that my user can download the file... <?php if (!isset($_GET)) die('Invalid Parameter'); include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.