Flash Messages in PHP

Sometimes during a redirect it is necessary to pass some information from one page to another. For example, to display some text for the user on the target page.

Such messages are called flash messages. This name was chosen because the message should appear only once, and disappear when the page is refreshed.

Let's implement the described functionality. Suppose on the page page.php we write a message to the session and perform a redirect to another page:

page.php<?php
  session_start();
  
  $_SESSION['flash'] = 'message';
  header('Location: index.php');
  die();
?>

On the page index.php we will display the message and delete it from the session to avoid showing it again:

index.php<?php
  session_start();
  
  if (isset($_SESSION['flash'])) {
    echo $_SESSION['flash'];
    unset($_SESSION['flash']);
  }
?>
Задание 1

Implement the described flash messages. Check their operation.