What method can be used to dynamically redirect users to different web pages based on form input in PHP?
To dynamically redirect users to different web pages based on form input in PHP, you can use the header() function to send a raw HTTP header to the browser, which will redirect the user to the specified URL. You can use a conditional statement to check the form input and determine which URL to redirect the user to.
<?php
if(isset($_POST['submit'])){
$input = $_POST['input']; // Assuming 'input' is the name of the form field
if($input == 'page1'){
header("Location: page1.php");
exit();
} elseif($input == 'page2'){
header("Location: page2.php");
exit();
} else {
header("Location: default.php");
exit();
}
}
?>
Related Questions
- How can PHP be utilized to create a download prompt for files, similar to executable files?
- How can PHP developers efficiently debug issues related to array manipulation and value replacement in their code?
- How can PHP be used to check for existing usernames and email addresses in a database before allowing a user to register?