I have a very basic question… In a php function I’m redirecting if a value returns FALSE otherwise continuing the code.
flibbertigibbet()
{
$value = true_or_false();
if ($value == FALSE)
{
//redirect to another controller method
}
//the rest of the code
}
What happens after the redirect? Does the code break or does a little execute if say.. the redirect takes longer to load?
Is it good practice to use exit() after redirects?
The code will continue to execute – not just when the redirect takes longer, but each time nd through to the end.
Whether you use
exit()depends on whether or not you want the rest of the code to be executed. You might set aheader()and send a new address, but you can still execute things afterwards – like updating a database or some other bits.I normally think it is best to do all your required updating and send the
header()right at the end of a page – makes debugging much easier and more intuitive.