relocation

27 September 2004

just before i make the same mistake i’ve made about every three days for the last heaven knows how long again… (file under: weblog as aide memoire.)

when you use the header function in php it doesn’t make the script stop what it’s doing and send the header. it just adds the header to a list of headers to be sent when the page is completely processed. and when the page is completely processed it seems to send the headers in reverse order. so if you’ve got something like:

<?php

if ($whatsit)

{

   header ("Location: $whatsitplace");

}

header ("Location: $nowhatsitplace");

?>

</pre>

what you actually end up with if $whatsit is true is to end up at $nowhatsitplace.   if you do this enough times you end up pulling all your hair out.



the thing to do is:



    <?php
    
    if ($whatsit)
    
    {
    
       header ("Location: $whatsitplace");
    
       die();
    
    }
    
    header ("Location: $nowhatsitplace");
    
    ?>
    
    </pre>
    
    that is, after you've figured out someplace you want to go, give up and go there.
    
      now i just have to remember this!