How can PHP be used to redirect to a specific HTML page based on form submission?
To redirect to a specific HTML page based on form submission in PHP, you can use the header() function to send a raw HTTP header to the browser. You can check the form submission using $_POST or $_GET superglobals and then redirect the user to the desired HTML page using the header() function with the "Location" parameter set to the URL of the page.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check if the form was submitted
if (isset($_POST['submit'])) {
// Redirect to a specific HTML page
header("Location: specific_page.html");
exit();
}
}
?>
Keywords
Related Questions
- What is the issue with the echo output in the PHP code provided?
- How can the use of mysqli_affected_rows() function be beneficial in determining the success of an INSERT query in PHP, and why is it recommended over mysql_affected_rows()?
- In what scenarios would it be recommended to use GD-Lib for thumbnail creation in PHP, despite the availability of other options?