How can PHP be used to redirect users to different pages based on form submission results?
To redirect users to different pages based on form submission results in PHP, you can use the header() function to send a raw HTTP header to the browser. You can set the Location header to the URL of the page you want to redirect the user to. Make sure to call the header() function before any output is sent to the browser.
<?php
// Process form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check form submission results
if ($form_result == "success") {
header("Location: success_page.php");
exit();
} else {
header("Location: error_page.php");
exit();
}
}
?>