ob_start & session_start

ob_start & session_start

am 08.12.2005 05:19:12 von Joe Harman

Hello,

Something just crossed my mind about using output buffering.... is
there any reason why you should start a session before calling
ob_start() ???

Just curious which way would be the proper way of doing it... or
doesn't it matter?

Thanks

--
Joe Harman
---------
* My programs never have bugs, they just develop random features.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: ob_start & session_start

am 08.12.2005 05:25:09 von Joe Harman

Okay.. makes sense after you spelled it out to me... LOL... I always
start my session first.. so, that must why i have never had any
problems

Cheers & Thanks!
Joe


On 12/7/05, Zack Bloom wrote:
> yes, it will display the content in the buffer before creating the sessio=
n.
> If your session uses cookies (this is usually automatically decided by ph=
p)
> it cannot send out the header after the buffer.
>
>
> On 12/7/05, Joe Harman wrote:
> >
> > Hello,
> >
> > Something just crossed my mind about using output buffering.... is
> > there any reason why you should start a session before calling
> > ob_start() ???
> >
> > Just curious which way would be the proper way of doing it... or
> > doesn't it matter?
> >
> > Thanks
> >
> > --
> > Joe Harman
> > ---------
> > * My programs never have bugs, they just develop random features.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>


--
Joe Harman
---------
* My programs never have bugs, they just develop random features.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: ob_start & session_start

am 08.12.2005 07:12:42 von Chris Shiflett

Joe Harman wrote:
> Okay...makes sense after you spelled it out to me.

That didn't make sense to me (and I missed the original reply). Mind
elaborating? :-)

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: ob_start & session_start

am 08.12.2005 07:23:03 von Zack Bloom

------=_Part_9590_232420.1134022983414
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Sure, ob_start begins a buffer allowing you to display content in the
browser before your script has finished executing. This is useful when
loading a time intensive page to tell the user to wait. When you create a
session (provide php is not configured otherwise) php attempts to store a
cookie with the session id that corisponds to the session file on the
server. If it cannot set this cookie it appends the session id to pages in
the get format. If you were to call session_start() after the output
buffering, content and consequentially the headers would have been already
sent to the browser. Since cookies must be set in the headers and the
headers must be set before any content is sent to the page, to use cookie
based sessions you must begin the session before the buffer.

Hope that cleared it up,

Zack Bloom


On 12/8/05, Chris Shiflett wrote:
>
> Joe Harman wrote:
> > Okay...makes sense after you spelled it out to me.
>
> That didn't make sense to me (and I missed the original reply). Mind
> elaborating? :-)
>
> Chris
>
> --
> Chris Shiflett
> Brain Bulb, The PHP Consultancy
> http://brainbulb.com/
>
> --
> PHP General Mailing List ( http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

------=_Part_9590_232420.1134022983414--

Re: ob_start & session_start

am 08.12.2005 07:23:40 von Joe Harman

I guess this was just out of general curiousity... If you started
'session_start()' after 'ob_start()' would the sessions work
correctly? k.. maybe I am still confused... lol... I normally do
session_start() before the ob_start()...

----
Zack Said : 'yes, it will display the content in the buffer before
creating the session. If your session uses cookies (this is usually
automatically decided by php) it cannot send out the header after the
buffer.'
----

So, the question is really... in what order is the best way to do
this... I would think that you always want to start a session first...
but then again, you guys are the experts... i am sure someone knows a
reason when you should not do that.

;o)
Joe




On 12/8/05, Chris Shiflett wrote:
> Joe Harman wrote:
> > Okay...makes sense after you spelled it out to me.
>
> That didn't make sense to me (and I missed the original reply). Mind
> elaborating? :-)
>
> Chris
>
> --
> Chris Shiflett
> Brain Bulb, The PHP Consultancy
> http://brainbulb.com/
>


--
Joe Harman
---------
* My programs never have bugs, they just develop random features.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: ob_start & session_start

am 08.12.2005 07:55:02 von Curt Zirzow

On Thu, Dec 08, 2005 at 01:23:40AM -0500, Joe Harman wrote:
>
> So, the question is really... in what order is the best way to do
> this... I would think that you always want to start a session first...
> but then again, you guys are the experts... i am sure someone knows a
> reason when you should not do that.

The first thing I would ask is why are you using/need ob_start().

session_start() should be the first thing that happens in most
cases. Since, well, any code that exist is potentially going to
rely on a session state.

If you are trying to use ob_start() to rid of the common error
'headers already sent in some_file.php on line such and such', i
would first consider why that is causing the error and how can you
call session_start() before that happens.

Since '97 i think i've used ob_start twice, in all my php apps, and
that was cause I wanted to filter the output either with tidy or
modify the data in a very obscure way.

Curt.
--
cat .signature: No such file or directory

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: ob_start & session_start

am 08.12.2005 08:18:16 von Chris Shiflett

Zack Bloom wrote:
> Sure, ob_start begins a buffer allowing you to display content in
> the browser before your script has finished executing.

Calling ob_start() turns on PHP's output buffering. In other words, it
buffers output from the moment this function is called until the buffer
is flushed (whether explicitly or because the script finishes).

As long as PHP is buffering the output, the client can't get it.

> This is useful when loading a time intensive page to tell the user
> to wait.

I think you might be thinking of flush(), which flushes PHP's output
buffer as well as the output buffer of the web server (or whatever
backend PHP is using).

> When you create a session (provide php is not configured otherwise)
> php attempts to store a cookie with the session id that corisponds
> to the session file on the server. If it cannot set this cookie it
> appends the session id to pages in the get format.

Yeah, PHP includes a Set-Cookie header in its response. If
session.use_trans_sid is enabled, it will also rewrite URLs to include
the session identifier. When PHP receives a request that includes a
session identifier, it knows whether the client accepts cookies.

if (session identifier in cookie)
{
cookies enabled
}
elseif (session identifier in URL)
{
cookies disabled
}
else
{
new user
}

> If you were to call session_start() after the output buffering,
> content and consequentially the headers would have been already
> sent to the browser.

Maybe you're getting the buffering and flushing concepts reversed? Think
of a toilet - buffering is the handle up, and flushing is the handle
down. :-)

Hope that helps!

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: ob_start & session_start

am 08.12.2005 08:41:20 von Zack Bloom

------=_Part_9962_6118762.1134027680915
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I have never tried it but if it did work i doubt it would use cookies, it
would probably pass it in the addresses or throw an error.

On 12/8/05, Joe Harman wrote:
>
> I guess this was just out of general curiousity... If you started
> 'session_start()' after 'ob_start()' would the sessions work
> correctly? k.. maybe I am still confused... lol... I normally do
> session_start() before the ob_start()...
>
> ----
> Zack Said : 'yes, it will display the content in the buffer before
> creating the session. If your session uses cookies (this is usually
> automatically decided by php) it cannot send out the header after the
> buffer.'
> ----
>
> So, the question is really... in what order is the best way to do
> this... I would think that you always want to start a session first...
> but then again, you guys are the experts... i am sure someone knows a
> reason when you should not do that.
>
> ;o)
> Joe
>
>
>
>
> On 12/8/05, Chris Shiflett wrote:
> > Joe Harman wrote:
> > > Okay...makes sense after you spelled it out to me.
> >
> > That didn't make sense to me (and I missed the original reply). Mind
> > elaborating? :-)
> >
> > Chris
> >
> > --
> > Chris Shiflett
> > Brain Bulb, The PHP Consultancy
> > http://brainbulb.com/
> >
>
>
> --
> Joe Harman
> ---------
> * My programs never have bugs, they just develop random features.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

------=_Part_9962_6118762.1134027680915--

Re: ob_start & session_start

am 08.12.2005 08:43:14 von Zack Bloom

------=_Part_9982_30014874.1134027794192
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Sorry it looked like the rest of your email was part of the previous one.
To answer your question it is better to call session_start() before
ob_start()

On 12/8/05, Zack Bloom wrote:
>
> I have never tried it but if it did work i doubt it would use cookies, it
> would probably pass it in the addresses or throw an error.
>
> On 12/8/05, Joe Harman wrote:
> >
> > I guess this was just out of general curiousity... If you started
> > 'session_start()' after 'ob_start()' would the sessions work
> > correctly? k.. maybe I am still confused... lol... I normally do
> > session_start() before the ob_start()...
> >
> > ----
> > Zack Said : 'yes, it will display the content in the buffer before
> > creating the session. If your session uses cookies (this is usually
> > automatically decided by php) it cannot send out the header after the
> > buffer.'
> > ----
> >
> > So, the question is really... in what order is the best way to do
> > this... I would think that you always want to start a session first...
> > but then again, you guys are the experts... i am sure someone knows a
> > reason when you should not do that.
> >
> > ;o)
> > Joe
> >
> >
> >
> >
> > On 12/8/05, Chris Shiflett wrote:
> > > Joe Harman wrote:
> > > > Okay...makes sense after you spelled it out to me.
> > >
> > > That didn't make sense to me (and I missed the original reply). Mind
> > > elaborating? :-)
> > >
> > > Chris
> > >
> > > --
> > > Chris Shiflett
> > > Brain Bulb, The PHP Consultancy
> > > http://brainbulb.com/
> > >
> >
> >
> > --
> > Joe Harman
> > ---------
> > * My programs never have bugs, they just develop random features.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>

------=_Part_9982_30014874.1134027794192--