473,386 Members | 1,828 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,386 software developers and data experts.

cannot modify header info, headers already sent

I have this section at the end of a page
-------------------
if ($_POST['assign']== 'Open in Excel'){

if (empty($data)) {
$data = "\n(0) Records Found!\n";}
header("Content-type: application/xmsdownload");
header("Content-Disposition: attachment; filename=".
$file_name.date("Y:m:d H:i").".xls");
header("Pragma: no-cache");
header("Expires; 0");

print "$header\n$data";

exit;

}else{
include "header.php";
include $template_path.$template;
include "footer.php";

}

Because the header.php is sent at the bottom of the page I can't have
the print to Excel output header in the if statement or I get the
message header already sent. I need the else statements where they
are because earlier in the code there are different selections of
templates depending on if a form is filled out so at the end it has to
display the right template.

Is there a way to send the excel output away from the page in a
function or something so that it processes the else?

thanks,
Oct 14 '08 #1
4 2535
JRough wrote:
I have this section at the end of a page
-------------------
if ($_POST['assign']== 'Open in Excel'){

if (empty($data)) {
$data = "\n(0) Records Found!\n";}
header("Content-type: application/xmsdownload");
header("Content-Disposition: attachment; filename=".
$file_name.date("Y:m:d H:i").".xls");
header("Pragma: no-cache");
header("Expires; 0");

print "$header\n$data";

exit;

}else{
include "header.php";
include $template_path.$template;
include "footer.php";

}

Because the header.php is sent at the bottom of the page I can't have
the print to Excel output header in the if statement or I get the
message header already sent. I need the else statements where they
are because earlier in the code there are different selections of
templates depending on if a form is filled out so at the end it has to
display the right template.

Is there a way to send the excel output away from the page in a
function or something so that it processes the else?

thanks,
Nope. Once you've sent ANYTHING to the client, the web server sends
default headers.

You can send an Excel file or HTML in a request - but not both.

As has been explained to you time and time again...

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

Oct 15 '08 #2
On Oct 14, 7:16*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I have this section at the end of a page
-------------------
if ($_POST['assign']== 'Open in Excel'){
* * * * * *if (empty($data)) {
* * * * * * * * * *$data = "\n(0) Records Found!\n";}
* *header("Content-type: application/xmsdownload");
* *header("Content-Disposition: attachment; filename=".
$file_name.date("Y:m:d H:i").".xls");
* *header("Pragma: no-cache");
* *header("Expires; 0");
* *print "$header\n$data";
* *exit;
}else{
include "header.php";
* *include $template_path.$template;
* *include "footer.php";
}
Because the header.php is sent at the bottom of the page I can't have
the print to Excel output header in the if statement or I get the
message header already sent. * I need the else statements where they
are because earlier in the code there are different selections of
templates depending on if a form is filled out so at the end it has to
display *the right template.
Is there a way to send the excel output away from the page in a
function or something so that it processes the else?
thanks,

Nope. *Once you've sent ANYTHING to the client, the web server sends
default headers.

You can send an Excel file or HTML in a request - but not both.

As has been explained to you time and time again...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Okay, then maybe I can figure out how to redirect the excel if/excel
output to another page. the problem is then I have to requery the
database and run through all these queries depending on what a user
puts in a form. Is there a way to send the one query for the
selection to the redirected page so I don't have to go through all of
that?
thanks,
Oct 15 '08 #3
Message-ID:
<c8**********************************@s9g2000prg.g ooglegroups.comfrom
JRough contained the following:
>Okay, then maybe I can figure out how to redirect the excel if/excel
output to another page. the problem is then I have to requery the
database and run through all these queries depending on what a user
puts in a form. Is there a way to send the one query for the
selection to the redirected page so I don't have to go through all of
that?
thanks,
The best way is to re-arrange your logic so that all processing is done
before any page output. This may involve temporarily storing the output
as variables. Once the logic is finished you can either redirect using
header() or echo the output variables.

Like Jerry says, you can't do both.
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk - http://4theweb.co.uk
Oct 15 '08 #4
I don't know every detail of your current logic, but I would think you
could just have the input on this page and have it post that
information (like you already are doing here) to another page where
all the processing is done first. That way you have only one file
that accesses the database because it's doing all the work... instead
of splitting everything up amongst this one page.
Oct 15 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
5
by: J Huntley Palmer | last post by:
I am getting this error: Cannot modify header information - headers already sent by when I issue a header ("Location: http://www.foobar.com"); How can I redirect the user to such a site...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
5
by: half21back | last post by:
Can anyone tell me what is wrong with this code? <?php if (isset($_COOKIE)) { $url = $row_rsCookieReferral; header("Location: $url"); } ?>
8
by: mcserret | last post by:
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...
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
3
by: TechnoAtif | last post by:
Hi All. I have got problem with the header. If i run my php script in the local host it runs perfectly but if i do the same on net after loading it via ftp. it gives following error: The code...
2
by: pks83 | last post by:
Hello I am also facing this problem when i amtrying to send additional header information. Warning: Cannot modify header information - headers already sent by (output started at header.php:96)...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...

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.