473,585 Members | 2,657 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("locatio n: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 2386
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("locatio n: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.goog legroups.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("locatio n: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("locatio n: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*******@attgl obal.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.ph p (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("locatio n: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********@gma il.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("locati on: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.ph p (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.comwro te:
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("locatio n: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_r egistered("SESS ION")){
$issession=1;
header("locatio n:www.foo.com/enterStuff.php" ); //logged in
}
else {
header("locatio n: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_d b($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($q ry) or die ("Query failed: " . mysql_error());

} else {

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

mysql_close($db h);

exit();
?>

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

<?php
header("locatio n: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
3164
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 message on my browser, why? Warning: Cannot add header information - headers already sent by (output started at /var/www/cookietest.php:2) in
3
3313
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 (after I set the appropriate $_SESSION value) but I get the following error: Warning: Cannot modify header information - headers already sent by (...)
4
2058
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 sun\css.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\loginmeth.php on line 24 This is the login script stored in loginmeth.php...
5
1990
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 header information - headers already sent by (output started at C:\Inetpub ........login\include\header.php:9) in...
2
12782
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 help me.
2
2315
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
1872
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 to connect to the Informix database I'm getting : Warning - Cannot retrieve the column code page info from the OLE DB provider ???
3
1418
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 User_Info_Other where user_id = '1'"); header("Content-type: image/gif"); while ($row = mysql_fetch_array($gotten)) {
10
2354
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 'connectdb.php'; $id = $_GET;
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8212
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.