What are some potential solutions for redirecting to a custom URL after a successful form submission in PHP?
When a form is submitted successfully in PHP, one common requirement is to redirect the user to a custom URL. This can be achieved by using the header() function in PHP to send a raw HTTP header for the redirect. The header() function should be called before any output is sent to the browser to avoid any errors.
// Process form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Handle form data
// Redirect to custom URL
header("Location: https://www.example.com/thank-you.php");
exit();
}
Keywords
Related Questions
- What are the best practices for formatting echo statements in PHP to ensure readability and maintainability of code?
- What are some best practices for handling form validation in PHP to prevent submitting empty fields?
- What are potential security risks associated with storing database access credentials in the htdoc folder?