How can PHP developers ensure that form data is not resubmitted when a user refreshes the page?

When a user refreshes a page after submitting a form, the form data may be resubmitted, leading to duplicate entries or unintended actions. To prevent this, PHP developers can use the Post/Redirect/Get (PRG) pattern. After processing the form data, the PHP script should redirect the user to a different page using the header() function. This way, when the user refreshes the page, they will only reload the redirected page without resubmitting the form data.

// Process form data
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Handle form submission
    
    // Redirect to a different page
    header("Location: success.php");
    exit;
}