A simple library for flash messages.

v3.0.1 2016-09-18 21:31 UTC

This package is not auto-updated.

Last update: 2021-11-27 01:41:58 UTC


By Joe Fallon

The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request. This is useful for passing error/success/warning/info messages to the user.

This library has the following features:

  • Fully unit tested.
  • Allows flash message to be stored in either the session or in a temporary variable.
  • They following types of flash messages can be stored: info, warning, success, and error.


The easiest way to install PHP Flash is with Composer. Create the following composer.json file and run the php composer.phar install command to install it.

    "require": {
        "joefallon/phpflash": "*"


Types of Messages

info    - Some event occurred that the user should be aware of.
warning - Something not good happened, but it isn't an error.
success - Whatever was attempted did, in fact, succeed.
error   - Some sort of program error occurred.

Working with Messages in the Session

To load and clear the messages that are in the session call the following:


Calling #loadMessagesFromSession is required because once PHP begins sending the page data back to the client, the session can no longer be accessed.

Info Messages

storeInfoMessage($message, $storeInSession = true)

Success Messages

storeSuccessMessage($message, $storeInSession = true)

Warning Messages

storeWarningMessage($message, $storeInSession = true)

Error Messages

storeErrorMessage($message, $storeInSession = true)

Example Usage on Two Separate Page Requests

$flash1 = new FlashMessages();
$flash1->storeInfoMessage('my info message', true);

later on the next request...

$flash2 = new FlashMessages();
$infoMessages = $flash2->retrieveInfoMessages();

Example Usage on the Same Page Request

$flash = new FlashMessages();
$flash->storeInfoMessage('my info message', false);

later on in the same request...

$infoMessages = $flash->retrieveInfoMessages();