How can PHP be used to redirect users to different pages based on form submission?
To redirect users to different pages based on form submission in PHP, you can use the header() function to send a raw HTTP header to the browser. You can use this function to specify the location where the user should be redirected after the form is submitted.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check which form was submitted
if ($_POST['form1']) {
header("Location: page1.php");
exit();
} elseif ($_POST['form2']) {
header("Location: page2.php");
exit();
} else {
header("Location: default_page.php");
exit();
}
}
?>
Related Questions
- Are there alternative methods to using overflow:scroll in PHP to enable scrolling within a table cell when including a file?
- What potential issues can arise when using the sleep() function in PHP to delay execution?
- How can the positioning of dynamically generated checkbox labels be controlled in PHP?