How can the issue of browser prompting to resend POST data be avoided in PHP?

When a user refreshes a page that was the result of a POST request, the browser prompts to resend the POST data, which can lead to duplicate form submissions or other unintended consequences. To avoid this issue, we can use the Post/Redirect/Get pattern in PHP. This involves processing the POST data, performing any necessary actions, and then redirecting the user to a new page using a GET request. This way, if the user refreshes the page, they will only be refreshing the GET request and not resubmitting the POST data.

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Process the POST data and perform necessary actions

    // Redirect to a new page using GET request
    header("Location: newpage.php");
    exit;
}
?>