⊗ppPmRdFM 408 of 447 menu

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:

<?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:

<?php session_start(); if (isset($_SESSION['flash'])) { echo $_SESSION['flash']; unset($_SESSION['flash']); } ?>

Implement the described flash messages. Check their operation.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline