Re: weird header() (bug may be)

From: Date: Thu, 12 Feb 2004 06:51:14 +0000
Subject: Re: weird header() (bug may be)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-177480@lists.php.net to get a copy of this message
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 ]

« previous php.general (#177480) next »