stdakov/flash

Simple php flash message library

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:Dockerfile

v1.0.0 2024-11-28 09:29 UTC

This package is not auto-updated.

Last update: 2024-12-13 09:15:34 UTC


README

This is supper simple implementation of php flash messages

Installation

The preferred way to install this tool is through composer.

Either run

php composer.phar require stdakov/flash

or add

"stdakov/flash": "*"

Usage

set message:

require 'vendor/autoload.php';

session_start();

use Dakov\FM;

if (isset($_POST['username']) && isset($_POST['password'])) {

    $user = getUser($_POST['username']);

    if ($user != null && isset($user['id']) && password_verify($_POST['password'], $user['password'])) {
        $_SESSION["USER"] = $user['id'];
        $hour = time() + 3600 * 24 * 365;
        setcookie('user_id', $user['id'], $hour);
    } else {
        FM::set("wrong_credentials", "Invalid credentials");
    }

    header("Location: /");
}

use the message:

<div>
    <?php if (FM::exist("wrong_credentials")): ?>
        <div class="alert alert-danger" role="alert">
            <?= FM::flash("wrong_credentials"); ?>
        </div>
    <?php endif; ?>
</div>

The MIT License (MIT)