Can PHP make a redirect call after executing a function? I am creating a function on the completion of which I want it to redirect to a file located in the same root folder. Can it be done?
if (...) {
// I am using echo here.
} else if ($_SESSION['qnum'] > 10) {
session_destroy();
echo "Some error occured.";
// Redirect to "user.php".
}
Yes, you would use the header function.
It is a good practice to call
exit()right after it so that code below it does not get executed.Also, from the documentation:
This means you should not echo anything right before the
header()function, as doing so will more than likely throw an error. Also, you will need to verify that this code gets run before any other output as well.