|
Posted by mercedes1954 on June 9, 2008, 11:02 am
Please log in for more thread options >
>
>
>
>
> > Hi,
>
> > I am using header("Location: in two places in my script, but they are
> > in mutually exclusive blocks i.e if one runs, the other can't.
>
> > However, an error is thrown pointing to the session_destroy() line
> > saying it started output. But it's not being called!
>
> > I removed the header() line below session_destroy() but it still gives
> > the same error so it seems to be session_destroy() existing in the
> > script even if not called.
>
> > if($loginmode=3D=3D"logout")
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 $_SESSION=3Darray();
> > =A0 =A0 =A0 =A0 if(isset($_COOKIE[session_name()]))
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 setcookie(session_name(),'',time() -4200=
0,'/');
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> > =A0 =A0 =A0 =A0 session_destroy();
>
> > =A0 =A0 =A0 =A0 header("Location: index.php");
> > =A0 =A0 =A0 =A0 exit;
> > =A0 =A0 =A0 =A0 }
>
> > // Another bhlock that can't run if the first block has......
>
> > if($errorMessage=3D=3D"")
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 // Set the $_SESSION variables for this logon
>
> > =A0 =A0 =A0 =A0 $_SESSION['loginuser']=3D$row['username'];
> > =A0 =A0 =A0 =A0 $_SESSION['loginlevel']=3D$row['level'];
>
> > =A0 =A0 =A0 =A0 header("Location: index.php");
> > =A0 =A0 =A0 =A0 exit;
> > =A0 =A0 =A0 =A0 }
>
> > How can I write the php script so that multiple header("Location:
> > options are present, or can co-exist with session_destroy() ?
>
> Not that I doubt you or anything, but what precisely stops the second
> block from running if the first one has run? Why can't there be
> something in $errorMessage just because $loginmode=3D=3D"logout"?
>
> Also, the complete error message will detail 2 lines, the one where
> output was started and the one that is trying to send more headers. Is
> the second reference to the header() line directly below the
> session_destroy()?
>
> Also, looking at your code in the first block, you seem to check for
> the presence of a session by checking for $_COOKIE[session_name()].
> However, even if you do not find this cookie, you still invoke
> session_destroy(). I would expect thhis to give an error along the
> lines of "Trying to destroy uninitialized session..." and this would
> certainly be some "output already sent".- Hide quoted text -
>
> - Show quoted text -
Thank you for the quick response. My brain tricked me into looking at
line 19 - where session_destroy() is - instead of realising it was
line 19 of a small include file that had 2 blank lines after the ?>
Now how many times did I read that in countless posts before turning
here for help???
Thanks for the other comments, but it was a vastly cut down piece of
code and the original addressed your concerns.
Thanks again for your time.
|