How can you prevent a message from being displayed again when a page is refreshed in PHP?

To prevent a message from being displayed again when a page is refreshed in PHP, you can use sessions to store a flag indicating whether the message has already been displayed. When the message is displayed, set the flag in the session. Then, on subsequent page loads, check this flag in the session before displaying the message again.

<?php
session_start();

if (!isset($_SESSION['message_displayed'])) {
    echo "Your message here";
    $_SESSION['message_displayed'] = true;
}
?>