[thelist] PHP Header oddness

Mark Groen evolt at markgroen.com
Fri Oct 7 09:18:09 CDT 2005


----- Original Message ----- 
From: "Steve Lewis" <>
To: <thelist at lists.evolt.org>
Sent: Friday, October 07, 2005 6:19 AM
Subject: [thelist] PHP Header oddness


> I find that when I turn off output_buffering, something strange
happens.
> I call it a bug.  I have a workaround, but I am curious, has anyone
else
> seen this issue and I am curious what you have done about it.
>
>      if($retval) {
>          $session->set('useredit', true);
>          header("Location: ".$session->get(Session::REFERRER));
>      }
>      /* Error found with form */
>      else {
>          $session->set('last_form', $form);
>          header("Location: ".$session->get(Session::REFERRER));
>      }
>
> Even though it is impossible to execute both header() statements, the
> PHP parser sees the first one and considers the request irrevocably
> modified, right then and there.  When the second line is parsed, it's
an
> error.  It's actually a warning, but a fatal-sounding one:
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
> /[...]/phproot/process.php:225) in
> /[...]/phproot/process.php on line 233

It's not really a bug afaik, as *any* error or undefined variable counts
as output. Not exactly sure which will work in your case, finessing
header('WWW-Authenticate: Negotiate') [http://ca.php.net/header] would
probably work, using ob_start() and ob_end_flush()  in your script will
work for sure.

Also check for blank space before and after the <?php ?> of course,
we've all missed that one. About the third note down on the docs there's
more info about the odd things header("Location:  do that may help.

cheers,

        Mark



More information about the thelist mailing list