PHPackages                             nassiry/flash-messages - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. nassiry/flash-messages

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

nassiry/flash-messages
======================

A PHP package for handling flash messages with session storage &amp; rendering.

v2.0.0(1y ago)8422↓75%2MITPHPPHP &gt;=7.4CI passing

Since Jan 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/nassiry/flash-messages)[ Packagist](https://packagist.org/packages/nassiry/flash-messages)[ RSS](/packages/nassiry-flash-messages/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Flash Messages
==============

[](#flash-messages)

[![Tests](https://github.com/nassiry/flash-messages/actions/workflows/tests.yml/badge.svg)](https://github.com/nassiry/flash-messages/actions/workflows/tests.yml/badge.svg)[![Packagist Downloads](https://camo.githubusercontent.com/c2344d3266ed4fee25230e35a495524fe8e8432aa0d64c8c66b83a3b366ffc54/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6173736972792f666c6173682d6d65737361676573)](https://camo.githubusercontent.com/c2344d3266ed4fee25230e35a495524fe8e8432aa0d64c8c66b83a3b366ffc54/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6173736972792f666c6173682d6d65737361676573)[![Packagist Version](https://camo.githubusercontent.com/54fa681b4810c10bcc5c03a325f06b105caf231c4fb1e36bd2c4356f2f8fa460/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6173736972792f666c6173682d6d65737361676573)](https://camo.githubusercontent.com/54fa681b4810c10bcc5c03a325f06b105caf231c4fb1e36bd2c4356f2f8fa460/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6173736972792f666c6173682d6d65737361676573)[![PHP](https://camo.githubusercontent.com/30da60ee026a505924b598ee10e72b4f78c52de0509ddad6d8574eb1b5713b08/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545372e342d626c7565)](https://camo.githubusercontent.com/30da60ee026a505924b598ee10e72b4f78c52de0509ddad6d8574eb1b5713b08/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545372e342d626c7565)[![License](https://camo.githubusercontent.com/18c39f5c5368cfba47955d158e77fdbe7d825564cfa6608b0608070065d41a4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e6173736972792f666c6173682d6d65737361676573)](https://camo.githubusercontent.com/18c39f5c5368cfba47955d158e77fdbe7d825564cfa6608b0608070065d41a4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e6173736972792f666c6173682d6d65737361676573)

A lightweight PHP library for handling flash messages with **session storage** &amp; simple **HTML** rendering. This package does not depend on any framework, but it can be integrated with frameworks like **Laravel**, **Symfony**, **CakePHP**, and **CodeIgniter** if needed.

### Features

[](#features)

- Session-based flash message storage.
- Instant message rendering.
- Custom message types.
- Fully framework-agnostic.

Table Of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)
    - [Default Usage (Display on Next Page Load)](#1-default-usage-display-on-next-page-load)
    - [Current Page Usage (Display Immediately)](#2-current-page-usage-display-immediately)
    - [Checking for Messages](#3-checking-for-messages)
    - [Retrieving Messages](#4-retrieving-messages)
    - [Rendering Messages](#5-rendering-messages)
    - [Clearing Messages](#6-clearing-messages)
3. [Adding Different Types of Messages](#adding-different-types-of-messages)
    - [Adding a custom type message](#adding-a-custom-type-message)
4. [Adding a custom type message](#custom-rendering-logic)
5. [Testing](#testing)
    - [Prerequisites](#1-prerequisites)
    - [Running Tests](#2-running-tests)
6. [License](#license)
7. [Contributing](#contributing)

Installation
------------

[](#installation)

The recommended way use Composer to install the package:

```
composer require nassiry/flash-messages

```

Usage
-----

[](#usage)

By default, the package stores messages in sessions to be displayed on the next page load.

### 1. Default Usage (Display on Next Page Load)

[](#1-default-usage-display-on-next-page-load)

```
require __DIR__ . '/vendor/autoload.php';

use Nassiry\FlashMessages\FlashMessages;

// Create an instance
$flash = FlashMessages::create();

// Add flash messages to be displayed on the next page load
$flash->success('Operation successful!');
$flash->error('An error occurred.');

// Render messages on the next page template file
$flash->render();
```

> **Note**: Ensure that `session_start();` has been called in your script before using.

### 2. Current Page Usage (Display Immediately)

[](#2-current-page-usage-display-immediately)

To display a message on the current page, set the second argument to `true` (default is `false`):

```
require __DIR__ . '/vendor/autoload.php';

use Nassiry\FlashMessages\FlashMessages;

// Create an instance
$flash = FlashMessages::create();

// Add flash messages to be displayed immediately
$flash->error('An error occurred.', true);

// Render messages instantly in the same page
$flash->render();
```

### 3. Checking for Messages

[](#3-checking-for-messages)

You can check if there are any stored messages:

```
// Check if ANY messages exist
if ($flash->hasMessages()) {
    echo "There are flash messages available.";
}

// Check if SPECIFIC TYPE messages exist
if ($flash->hasMessages('info')) {
    echo "There are info messages available.";
}
```

### 4. Retrieving Messages

[](#4-retrieving-messages)

You can retrieve all stored messages as an array:

```
// Get ALL messages
$allMessages = $flash->getMessages();
foreach ($allMessages as $message) {
    echo $message['type'] . ': ' . $message['message'] . "";
}

// Get messages of SPECIFIC TYPE
$infoMessages = $flash->getMessages('info');
if (!empty($infoMessages)) {
    foreach ($infoMessages as $message) {
        echo 'Info: ' . $message['message'] . "";
    }
} else {
    echo "No info messages found.";
}
```

### 5. Rendering Messages

[](#5-rendering-messages)

Outputs all flash messages with default HTML structure

```
$flash->render();
```

```
Operation successful!
An error occurred!
```

### 6. Clearing Messages

[](#6-clearing-messages)

To clear all stored messages:

```
$flash->clear();
```

### Adding Different Types of Messages

[](#adding-different-types-of-messages)

Currently, the package support following message types.

- `$flash->success('Success message!');`
- `$flash->error('Error message!');`
- `$flash->info('Informational message!');`
- `$flash->warning('Warning message!');`

#### Adding a custom type message

[](#adding-a-custom-type-message)

- `addCustomType(string $type, string $message, bool $instant = false)`

```
$flash->addCustomType('notification',
 'This is a custom notification message!',
  true
 );
$flash->addCustomType('alert',
 'This is an alert message!',
  false
);
```

### Custom Rendering Logic

[](#custom-rendering-logic)

If you need to customize the way messages are displayed, extend the `FlashMessageRenderer` class:

```
use Nassiry\FlashMessages\FlashMessageRenderer;

class CustomRenderer extends FlashMessageRenderer
{
    public function renderMessage(string $type, string $message): void
    {
        echo sprintf('%s', htmlspecialchars($type), htmlspecialchars($message));
    }
}

$renderer = new CustomRenderer();
$flash = new FlashMessages(new FlashMessageStorage(), $renderer);
$flash->success('Custom rendered message!');
$flash->render();
```

### Testing

[](#testing)

Run the unit tests to ensure the package works as expected:

#### 1. Prerequisites

[](#1-prerequisites)

Ensure you have all dependencies installed by running:

```
composer install

```

#### 2. Running Tests

[](#2-running-tests)

Execute the following command to run the test suite:

```
composer test

```

### License

[](#license)

This package is open-source software licensed under the [MIT license](LICENSE).

### Contributing

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request or open an issue.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance44

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

499d ago

Major Versions

v1.0.0 → v2.0.02025-01-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d313e55474ce48c3b19820c784435215bb56c4497557b603583dcf59ba2270c?d=identicon)[nassiry](/maintainers/nassiry)

---

Top Contributors

[![nassiry](https://avatars.githubusercontent.com/u/105405739?v=4)](https://github.com/nassiry "nassiry (10 commits)")

---

Tags

flash-messagesflash-renderingnotificationsphp-flashphp-notificationsphp-sessionsphp-simple-flashesphp-simple-notificationssession-messagesflash messagephp flashsession-messagerender-flashes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nassiry-flash-messages/health.svg)

```
[![Health](https://phpackages.com/badges/nassiry-flash-messages/health.svg)](https://phpackages.com/packages/nassiry-flash-messages)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[eduardokum/laravel-mail-auto-embed

Library for embed images in emails automatically

1702.0M5](/packages/eduardokum-laravel-mail-auto-embed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
