What is the best practice for handling a redirect to another page after a successful form submission in PHP?
After a successful form submission in PHP, it is best practice to redirect the user to another page to prevent form resubmission on page refresh. This can be achieved by using the header() function in PHP to send a Location header with the URL of the page to redirect to.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Process form data
// Redirect to another page after successful form submission
header("Location: success.php");
exit();
}
?>
Keywords
Related Questions
- Are there any specific PHP functions or methods that can help maintain form data during navigation?
- How can the header() function be used to redirect a user to a different page after a certain amount of time in PHP?
- How can beginners differentiate between PHP as a programming language and HTML as a markup language?