1. Go to this page and download the library: Download edydeyemi/session-messages library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
edydeyemi / session-messages example snippets
// 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();
$msg->error('This is an error message', 'http://yoursite.com/another-page');
$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');
if ($msg->hasErrors()) {
// There are errors, so do something like redirect
}
// 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()) {
...
}