By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,723 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,723 IT Pros & Developers. It's quick & easy.

Please help: "header already sent" error

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
["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

P: n/a
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

P: n/a
[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

P: n/a
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

P: n/a
[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 discussion thread is closed

Replies have been disabled for this discussion.