473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2552
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*******@attgl obal.net
=============== ===

Oct 15 '08 #2
On Oct 14, 7:16*pm, Jerry Stuckle <jstuck...@attg lobal.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("Conten t-type: application/xmsdownload");
* *header("Conten t-Disposition: attachment; filename=".
$file_name.date ("Y:m:d H:i").".xls");
* *header("Pragma : no-cache");
* *header("Expire s; 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...@attgl obal.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************ *************** *******@s9g2000 prg.googlegroup s.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 011000100110110 0010000000110
001101101011011 001000110111101 100111001011
100110001101101 111001011100111 010101101011
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
5473
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
5
625
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 without encountering this error. If I run the same code on two sites I will get the error on one site but not the other.
19
7920
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 limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
5
2627
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
2392
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 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
2
2321
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
1592
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 goes like this: <html> <title>CMS:Search Product</title> <body>
2
1483
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) in my.class.php on line 1198 What is happening over here is that i when i am trying to download an attached file i am passing the additional header information which is conflicting with the header info which has already being sent before. ...
10
2369
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
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7725
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4369
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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
2
2329
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.