How can PHP be used to prevent users from reloading a page using the F5 key or browser button?

To prevent users from reloading a page using the F5 key or browser button, you can use PHP session variables to track whether the page has already been loaded. By setting a session variable when the page is loaded and checking for its existence on subsequent loads, you can redirect users back to the original page if they try to reload it.

<?php
session_start();

// Check if session variable is set
if(isset($_SESSION['page_loaded'])){
    // Redirect back to the original page
    header('Location: original_page.php');
    exit;
}

// Set session variable to indicate page has been loaded
$_SESSION['page_loaded'] = true;
?>