Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cannot modify header info, headers already sent

0 views
Skip to first unread message

JRough

unread,
Oct 14, 2008, 7:09:06 PM10/14/08
to
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,

Jerry Stuckle

unread,
Oct 14, 2008, 10:16:06 PM10/14/08
to

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.
jstu...@attglobal.net
==================

JRough

unread,
Oct 14, 2008, 11:32:20 PM10/14/08
to
> 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,

Geoff Berrow

unread,
Oct 15, 2008, 2:55:30 AM10/15/08
to
Message-ID:
<c8b8ff47-ba0c-4136...@s9g2000prg.googlegroups.com> from
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

transpar3nt

unread,
Oct 15, 2008, 3:31:50 PM10/15/08
to
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.
0 new messages