This is a discussion on Please help: "header already sent" error within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All How can I produce an output to the browser and let the script continue to work in the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
On Thu, 29 Apr 2004 12:05:56 +0200
Jerry <none@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(). |
|
|||
|
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" <none@none.com> wrote in message news:5dk1905cucloviuq1qkvk4p7hl52rqr5m1@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. |
|
|||
|
"Dasher" <someone@hotmail.com> wrote in message news:<8YudndHEW91xWgzdRVn-hQ@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 |
|
|||
|
["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 : |
|
|||
|
Pedro Graca <hexkid@hotpop.com> wrote in message news:<c70ilf$haiin$2@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 |
|
|||
|
[Off topic....]
r.shekhar@gmail.com (Raj Shekhar) wrote in message news:<7983ccf3.0405020358.565f1bb5@posting.google. com>... > Pedro Graca <hexkid@hotpop.com> wrote in message news:<c70ilf$haiin$2@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 |
|
|||
|
ng4rrjanbiah@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<abc4d8b8.0405022059.712fc4c4@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 |
|
|||
|
[Off topic...]
r.shekhar@gmail.com (Raj Shekhar) wrote in message news:<7983ccf3.0405042356.1ed62cfc@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 |