PHPackages                             edydeyemi/session-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. edydeyemi/session-messages

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

edydeyemi/session-messages
==========================

Simple-to-use Session-based FlashMessages Library for PHP with support for Boostrap 4 and Boostrap 5. A fork of Plasticbrain's session-based FlashMessages

v1(1y ago)0345[1 PRs](https://github.com/Edydeyemi/PhpSessionMessages/pulls)MITPHPPHP &gt;=5.4.0

Since Dec 7Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP Session-Based Messages
==========================

[](#php-session-based-messages)

Keep messages in session data until they are retrieved. Supports Bootstrap 4 or Bootstrap 5.

Notice
------

[](#notice)

This is a forked version of new version of PlasticBrain's PHPFlashMessages - . This forked version has support for both Bootstrap V4 and Bootstrap V5

Features
--------

[](#features)

- Namespaced
- PSR-4 autoload compliant
- Installable with composer
- Works with Bootstrap4 or Bootstrap 5
- Fully customizable messages
- URL redirects

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

[](#installation)

### With Composer

[](#with-composer)

```
composer require Edydeyemi/session-messages
```

### Without composer

[](#without-composer)

Download [SessionMessages.php](https://raw.githubusercontent.com/edydeyemi/PhpSessionMessages/master/src/SessionMessages.php) and save it to your project directory.

Import the file:

```
require '/path/to/SessionMessages.php';
```

Basic Usage
-----------

[](#basic-usage)

Default theme is Bootstrap V5. Pass 4 into the contructor to switch to Bootstrap V4.

```
// Start a Session
if (!session_id()) @session_start();

// Instantiate the class
$msg = new \Edydeyemi\SessionMessages\SessionMessages();
    or
$msg = new \Edydeyemi\SessionMessages\SessionMessages(4);

// Add messages
$msg->info('This is an info message');
$msg->success('This is a success message');
$msg->warning('This is a warning message');
$msg->error('This is an error message');

// If you need to check for errors (eg: when validating a form) you can:
if ($msg->hasErrors()) {
	// There ARE errors
} else {
  // There are NOT any errors
}

// Wherever you want to display the messages simply call:
$msg->display();
```

#### Message Type Constants

[](#message-type-constants)

Each message type can be referred to by its constant: INFO, SUCCESS, WARNING, ERROR. For example:

```
$msg::INFO
$msg::SUCCESS
$msg::WARNING
$msg::ERROR
```

### Redirects

[](#redirects)

It's possible to redirect to a different URL before displaying a message. For example, redirecting back to a form (and displaying an error message) so a user can correct an error.

The preferred method of doing this is by passing the URL as the 2nd parameter:

```
$msg->error('This is an error message', 'http://yoursite.com/another-page');
```

A redirect is executed as soon as the message it's attached to is queued. As such, if you need multiple messages AND need to redirect then include the URL with the last message:

```
$msg->success('This is a success message');
$msg->success('This is another success message');
$msg->error('This is an error message', 'http://redirect-url.com');
```

Helper Methods
--------------

[](#helper-methods)

### `hasErrors()`

[](#haserrors)

Check to see if there are any queued `ERROR` messages.

```
if ($msg->hasErrors()) {
    // There are errors, so do something like redirect
}
```

### `hasMessages ( [string $type] )`

[](#hasmessages--string-type-)

Check to see if there are any specific message types (or any messages at all) queued.

```
// Check if there are any INFO messages
if ($msg->hasMessages($msg::INFO)) {
    ...
}

// Check if there are any SUCCESS messages
if ($msg->hasMessages($msg::SUCCESS)) {
    ...
}

// Check if there are any WARNING messages
if ($msg->hasMessages($msg::WARNING)) {
    ...
}

// Check if there are any ERROR messages
if ($msg->hasMessages($msg::ERROR)) {
    ...
}

// See if there are *any* messages queued at all
if ($msg->hasMessages()) {
    ...
}
```

### `setCloseBtn ( string $html )`

[](#setclosebtn--string-html-)

Sets the HTML for the close button that's displayed on (non-sticky) messages.

```
$msg->setCloseBtn('
                        &amp;times;
                    ')
```

### `setCssClassMap ( array $cssClassMap )`

[](#setcssclassmap--array-cssclassmap-)

Sets the CSS classes that are used for each specific message type.

```
$msg->setCssClassMap([
    $msg::INFO    => 'alert-info',
    $msg::SUCCESS => 'alert-success',
    $msg::WARNING => 'alert-warning',
    $msg::ERROR   => 'alert-danger',
]);
```

### `setMsgAfter ( string $msgAfter )`

[](#setmsgafter--string-msgafter-)

Add a string of text (HTML or otherwise) **after** the message (but **inside** of the wrapper.)

For example, wrap a message in `` tags:

```
$msg->setMsgAfter('')
```

### `setMsgBefore ( string $msgBefore )`

[](#setmsgbefore--string-msgbefore-)

Add a string of text (HTML or otherwise) **before** the message (but **inside** of the wrapper.)

For example, wrap a message in `` tags:

```
$msg->setMsgBefore('')
```

### `setMsgCssClass ( [string $cssClass] )`

[](#setmsgcssclass--string-cssclass-)

Sets the CSS class that is applied to all messages, regardless of their type.

```
$msg->setMsgCssClass('alert')
```

### `setMsgWrapper ( string $html )`

[](#setmsgwrapper--string-html-)

Sets the HTML that wraps each message. HTML should include two placeholders (`%s`) for the CSS class and message text.

```
$msg->setMsgWrapper("%s")
```

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2023 Edydeyemi &amp;&amp; SoftMage Solutions

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

License
-------

[](#license-1)

The MIT License (MIT)

Copyright (c) 2015 Mike Everhart &amp; PlasticBrain Media LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance40

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

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

Unknown

Total

1

Last Release

518d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b4a20da32d5dea4afa4c63184522b38213b5673ccfdcc06efea31238b7bec813?d=identicon)[Edydeyemi](/maintainers/Edydeyemi)

---

Top Contributors

[![Edydeyemi](https://avatars.githubusercontent.com/u/22768186?v=4)](https://github.com/Edydeyemi "Edydeyemi (3 commits)")

---

Tags

phpsessionflashmessagesflash-messagesbootstrap5bootstrap4session messages

### Embed Badge

![Health badge](/badges/edydeyemi-session-messages/health.svg)

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

###  Alternatives

[plasticbrain/php-flash-messages

A modern take on PHP session-based flash messages

184229.6k8](/packages/plasticbrain-php-flash-messages)[cartalyst/alerts

Alerts allows you to easily pass alert messages to your Laravel views.

3064.2k](/packages/cartalyst-alerts)

PHPackages © 2026

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