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

Please help: "header already sent" error

Hi All

How can I produce an output to the browser and let the script continue
to work in the background, producing a later screen output?

Example:
Trigger a database search so that the user immediately sees a
"...searching..." screen while the script actually searches and later
on outputs the result.

I always get a "header already sent" error.

Your help is greatly appreciated.
Jerry.
Jul 17 '05 #1
8 2124
On Thu, 29 Apr 2004 12:05:56 +0200
Jerry <no**@none.com> wrote:
Hi All

How can I produce an output to the browser and let the script
continue to work in the background, producing a later screen output?

Example:
Trigger a database search so that the user immediately sees a
"...searching..." screen while the script actually searches and
later on outputs the result.

I always get a "header already sent" error.


Hi Jerry, see http://php.net/flush because it sounds like that this is
what you want. flush() will simply flush some output to the webserver
which in turn will flush to the browser at some point which in turn
will display some text to the user.

If you

echo 'searching...';
flush()

sleep(60);

then not necessarily the user will read ``searching...'' because as I
said, the webserver still buffers something and the browser too. So if
you wanna make sure, you need to find out how much you need to output
to make sure that the user will see something. You can just not care
and print some good amount of text to be sure that at least the string
``searching...'' will be displayed.

Now, ``header already sent'' is something else. After you output
anything to the webserver, it creates the headers of the HTTP answer
and will not go back to that step just because you want add a cookie,
a location or something. So, after echo/print/flush anything, do not
use header()/setcookie().

Jul 17 '05 #2
all of the code that is to be pre-header must be the very first code...
before anything else... e.g.

<?php
session_start();
header("Cache-control: private");
$_SESSION['SIndex']= 0;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
"Jerry" <no**@none.com> wrote in message
news:5d********************************@4ax.com...
Hi All

How can I produce an output to the browser and let the script continue
to work in the background, producing a later screen output?

Example:
Trigger a database search so that the user immediately sees a
"...searching..." screen while the script actually searches and later
on outputs the result.

I always get a "header already sent" error.

Your help is greatly appreciated.
Jerry.

Jul 17 '05 #3
"Dasher" <so*****@hotmail.com> wrote in message news:<8Y********************@comcast.com>...
all of the code that is to be pre-header must be the very first code...
before anything else... e.g.

<?php
session_start();
header("Cache-control: private");
$_SESSION['SIndex']= 0;
?>


I must point out that you should have no empty lines after '<?php'
part. i.e.
<?php
_EMPTY_LINE_
session_start();
...

will cause an error.

See http://www.faqts.com/knowledge_base/...d/13713/fid/51
for a better explanation

Regards
Jul 17 '05 #4
["Followup-To:" header set to comp.lang.php.]
Raj Shekhar wrote:
I must point out that you should have no empty lines after '<?php'
part. i.e.
<?php
_EMPTY_LINE_
session_start();
..

will cause an error.


You can have empty lines between the php tags.
You cannot have empty lines *before* the php start tag; that will start
outputting content (empty lines) to the browser.

1
2 <?php
3
4 /* lines 1 and 3 empty */
5 session_start();

will give the "output already started" error because of line 1.
If you remove line 1, line 3 (now line 2) will not give the error.


[OT] How do you like Google mail? [/OT]
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #5
Pedro Graca <he****@hotpop.com> wrote in message news:<c7************@ID-203069.news.uni-berlin.de>...
["Followup-To:" header set to comp.lang.php.]
You can have empty lines between the php tags.
You cannot have empty lines *before* the php start tag; that will start
outputting content (empty lines) to the browser.

1
2 <?php
3
4 /* lines 1 and 3 empty */
5 session_start();

will give the "output already started" error because of line 1.
If you remove line 1, line 3 (now line 2) will not give the error.
Hmmm.. I was confused. Thanks for the correction.


[OT] How do you like Google mail? [/OT]


Pretty awesome. One of the main problems with a web based mail account
like yahoo is that you cannot see threads of the emails. Gmail calls
threads as conversations. All messages are grouped with the original
message, creating a single conversation. Its much better than
threading.

And also you have the 1 GB storage space and the google search to
search through it. All in a all, a nifty package.

Regards
Raj Shekhar
Jul 17 '05 #6
[Off topic....]
r.*******@gmail.com (Raj Shekhar) wrote in message news:<79**************************@posting.google. com>...
Pedro Graca <he****@hotpop.com> wrote in message news:<c7************@ID-203069.news.uni-berlin.de>...
[OT] How do you like Google mail? [/OT]


Pretty awesome. One of the main problems with a web based mail account
like yahoo is that you cannot see threads of the emails. Gmail calls
threads as conversations. All messages are grouped with the original
message, creating a single conversation. Its much better than
threading.

And also you have the 1 GB storage space and the google search to
search through it. All in a all, a nifty package.


Are you aware of this <http://www.privacyrights.org/ar/GmailLetter.htm> ?

BTW, how could you get this email address?

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #7
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<ab**************************@posting.google. com>...

Are you aware of this <http://www.privacyrights.org/ar/GmailLetter.htm> ?
Thanks for the link. I know that there has been lot of noise about the
privacy issues in Gmail. Hoever I will be mailing lists and other not
so conidential mails. For others, I can use GPG from a POP mail
account. So frankly speaking I am not that concerned about the privacy
issues. The text ads are placed on the side and are not intrusive.

BTW, how could you get this email address?


One of my friends got a invite code from gmail and he kindly sent it
to me

Regrads
Raj Shekhar
Jul 17 '05 #8
[Off topic...]

r.*******@gmail.com (Raj Shekhar) wrote in message news:<79**************************@posting.google. com>...
<snip>

BTW, how could you get this email address?


One of my friends got a invite code from gmail and he kindly sent it
to me


Oh, that's great :)

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #9

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

Similar topics

1
by: Danny Anderson | last post by:
Hola, PHP folk! I have a php page that contains a self-processing form. The form holds search results. The search terms originally came from the previous page, but the user can repeatedly...
11
by: Francisco Mendez | last post by:
I get the following message when trying to run my script: "Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/newcustomer.php:23) in...
6
by: bissatch | last post by:
Hi, I am trying to use the following function: header("Location: http://www.mysite.co.uk/home/update/index.php"); ....but getting the following error: Warning: Cannot modify header...
16
by: a | last post by:
Hi everybody, My config: Win XP (or 2003), Apache 2.0.54, PHP 5.1.2. I have been trying to handle the case of a lenghty opearation on the server while providing the user with feedback and...
21
by: cman | last post by:
does anyone know why i can't generate images with: header("Content-type:image/jpeg"); imagejpeg($img_number); i've tried different examples but i always get a text output as if the header...
10
by: universalbitmapper | last post by:
Hi, I'm trying a simple form.html that call a .html script that begins with: <?php header("This is a test"); ?> When I click on the link, I get blank page.
4
by: three-eight-hotel | last post by:
I'm somewhat of a newbie to PHP coding, but have developed a site using the technology, and have been pleasantly surprised by the capabilities offered. I am more comfortable in the ASP world,...
11
by: ririe | last post by:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Inovasi\get_file.php:2) in C:\xampp\htdocs\Inovasi\get_file.php on line 40 Warning: Cannot...
2
by: kelvinwebdesigner | last post by:
Hi everybody. Im currently developing an application where users can upload files and later get acess to the url. Im now having this trouble with header Cannot modify header information – headers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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...
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.