Please help: "header already sent" error

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-29-2004
Jerry
 
Posts: n/a
Default 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.
Reply With Quote
  #2 (permalink)  
Old 04-30-2004
Kelly Thompson
 
Posts: n/a
Default Re: Please help: "header already sent" error

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().

Reply With Quote
  #3 (permalink)  
Old 04-30-2004
Dasher
 
Posts: n/a
Default Re: Please help: "header already sent" error

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.



Reply With Quote
  #4 (permalink)  
Old 05-01-2004
Raj Shekhar
 
Posts: n/a
Default Re: Please help: "header already sent" error

"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
Reply With Quote
  #5 (permalink)  
Old 05-01-2004
Pedro Graca
 
Posts: n/a
Default Re: Please help: "header already sent" error

["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 :
Reply With Quote
  #6 (permalink)  
Old 05-02-2004
Raj Shekhar
 
Posts: n/a
Default Re: Please help: "header already sent" error

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
Reply With Quote
  #7 (permalink)  
Old 05-03-2004
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Please help: "header already sent" error

[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
Reply With Quote
  #8 (permalink)  
Old 05-05-2004
Raj Shekhar
 
Posts: n/a
Default Re: Please help: "header already sent" error

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
Reply With Quote
  #9 (permalink)  
Old 05-05-2004
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Please help: "header already sent" error

[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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:47 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0