How can PHP be used to redirect to a new page after submitting a form?
After submitting a form in PHP, you can use the header() function to redirect the user to a new page. This function sends a raw HTTP header to the browser, which tells it to navigate to the specified URL. Make sure to call the header() function before any output is sent to the browser to avoid any errors.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Process your form data here
// Redirect to a new page
header("Location: new_page.php");
exit();
}
?>
Related Questions
- What are the advantages and disadvantages of using different file formats like csv, ini, or XML for data storage in PHP?
- How can PHP's built-in functions like print_r and mysql_affected_rows be effectively utilized in array processing and database updates?
- What are some best practices for passing criteria to a PHP class during initialization?