How can one prevent a script from running again when a page is reloaded in PHP?

To prevent a script from running again when a page is reloaded in PHP, you can use session variables to set a flag once the script has been executed, and then check for this flag before running the script again. This way, the script will only run once per session.

<?php
session_start();

if (!isset($_SESSION['script_has_run'])) {
    // Your script logic here

    // Set flag to indicate script has run
    $_SESSION['script_has_run'] = true;
}
?>