How can PHP be used to redirect users to specific pages based on form submissions?
To redirect users to specific pages based on form submissions in PHP, you can use the header() function to send a raw HTTP header to the browser. You can check the form data submitted by the user and then use a conditional statement to determine which page to redirect the user to.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($_POST["form_field"] == "value1") {
header("Location: page1.php");
exit;
} elseif ($_POST["form_field"] == "value2") {
header("Location: page2.php");
exit;
} else {
header("Location: default_page.php");
exit;
}
}
?>
Related Questions
- How can individual lines of text be processed and centered using imagettftext() in PHP?
- Is there a PHP library or framework that provides pre-built solutions for creating collapsible directory trees on a website?
- What are the limitations of achieving true simultaneous sending and receiving on a serial interface using PHP, and how can they be addressed?