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();
}