What are the best practices for handling page refreshes in PHP applications?

When handling page refreshes in PHP applications, it is important to prevent duplicate form submissions and unwanted actions that may occur when a user refreshes a page. One common approach is to use the Post/Redirect/Get pattern, where after processing a form submission, the user is redirected to a new page to prevent form resubmission on refresh.

// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Process form data
    
    // Redirect to a new page to prevent form resubmission on refresh
    header("Location: success.php");
    exit();
}