How can the echo statement for refreshing a page be executed only once in PHP?

To ensure that the echo statement for refreshing a page is executed only once in PHP, you can use a conditional check to determine if the page has been refreshed before echoing the statement. This can be achieved by setting a session variable upon the initial load of the page and checking for its existence before echoing the refresh statement.

<?php
session_start();

if (!isset($_SESSION['refreshed'])) {
    echo "<meta http-equiv='refresh' content='0'>";
    $_SESSION['refreshed'] = true;
}
?>