On Thu, Feb 12, 2004 at 05:20:29PM +1100, adwinwijaya wrote: > Hello php-generaler's , > > I have a script like this : > > if($foo == 'something'){ > header('Location:to_another_page.php') ; > }else > { > do another thing in here > } > > header('Location:to_previous_page.php'); > > > I got a problem ... when $foo == 'something' .. it wont redirect me > to to_another_page.php .... but if I put die(); after calling > header(); .. it will work ...
The reason it works after you put die() after calling your first header() is because once you send the location header, you can't send other stuff. Using die() causes script execution to end, which lets the header work. So put something in there that causes script execution to end (e.g., exit()). The proper code (including the properly-formed URL mentioned by others) is something like: if($foo == 'something'){ header('Location: http://www.example.com/to_another_page.php') ; exit(); }else { do another thing in here } header('Location: http://www.example.com/to_previous_page.php'); exit(); // for good measure joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php