Re: A stupid question?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jan 18, 2008 10:49 AM, Jochem Maas <jochem@xxxxxxxxxxxxx> wrote:
>
> Eric Butera schreef:
> > On Jan 18, 2008 9:31 AM, Jochem Maas <jochem@xxxxxxxxxxxxx> wrote:
> >> Eric Butera schreef:
> >>> On Jan 17, 2008 9:54 PM, Shelley Shyan <Shelley.Shyan@xxxxxxxxxxxxx> wrote:
> >>>> Hi all,
> >>>>
> >>>> Maybe this is a somehow stupid question.
> >>>>
> >>>> I want to know how php could know whether session_start() has been called, that is, whether session has been started.
> >>>>
> >>>> I Googled, but got little help.
> >>>>
> >>>> Thank you for help!
> >>>> Any tip is greatly appreciated.
> >>>>
> >>>> Regards,
> >>>> Shelley
> >>>>
> >>>>
> >>>
> >>> One other thing is you won't be able to start a session if headers
> >>> have been sent.  It is a good idea to use output buffering to help aid
> >>> with this.
> >> no it's not a good idea to use output bufferin to 'help aid' this. instead
> >> write code that is logically structured so that the initialization of your pages/app/scripts
> >> occurs BEFORE any output is generated.
> >>
> >> to avoid spurious output of whitespace avoid including the trailing '?>' is
> >> included php[-only] files. (and ignore whatever Tedd says on the subject ;-)
> >>
> >>> If headers have been sent you'll get a nasty warning.
> >> if (headers_sent()) {
> >>         echo "oops!";
> >> }
> >>
> >> use code to avoid warnings.
> >>
> >>
> >>> It can be a php.ini setting or you can simply call ob_start() on the
> >>> first line of your script.
> >>>
> >>
> >
> > I agree with you that it is ideal to do what you're saying but it
> > isn't always 100% practical.  Sometimes the stuff we work on is handed
> > down and in our purist world we'd like to change it, but can't.  So I
> > think that you should recommend best practices for future creations,
> > but blindly shooting down all alternatives isn't right.  My solution
> > would get the job done rather than the OP refactoring the pages and
> > not getting paid for it.  It would work and over time things could be
> > tidied up on future revisions over time.
>
> still, it's not a good idea because that implies a concept that you are
> wanting to apply. you don't want to use output buffering if you can help it.
>
> output buffering to overcome output being created before headers are [conditionally]
> sent in badly written code is a viable hack given certain budgetary and/or time
> constraints.
>
> what I'm saying is it's a viable solution to a immediate problem for
> which you don't have the time/money to fix properly - it's more than fine
> to enlighted the OP as such, I just don't think calling it a good idea
> is the right thing to do - it gives the impression that your giving
> it the seal-of-good-coding-practice-approval, and the OP might just take
> your word for it.
>
> > Also, if you do what you've said and created your logic 100%
> > perfectly, there should never be any use for headers_sent(), right?
> > Headers shouldn't have been sent until you've specifically sent them.
>
> true, and they are not - but if you want to be sure to avoid cruft in the
> output and/or shit in the logs you program defensively for those occasions
> where somebody [else?] makes a mistake of some kind.
>

Fair enough, you win!  :)

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux