How can a user be notified that the page is no longer valid after reloading?

When a user reloads a page that is no longer valid, it is important to notify them of this change to prevent confusion. One way to do this is by setting a session variable when the page becomes invalid, and then checking for this variable on page load. If the variable is present, display a message to the user informing them that the page is no longer valid.

// Set session variable when page becomes invalid
$_SESSION['page_valid'] = false;

// Check for session variable on page load
if(isset($_SESSION['page_valid']) && $_SESSION['page_valid'] == false) {
    echo "This page is no longer valid. Please navigate to a different page.";
}