How can PHP be used to redirect to a different page based on form input validation?
To redirect to a different page based on form input validation in PHP, you can use the header() function to send a raw HTTP header to the browser. You can check the form input validation condition and then redirect the user to a different page accordingly.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Perform form input validation
if (/* validation condition */) {
header("Location: success.php");
exit;
} else {
header("Location: error.php");
exit;
}
}
?>