Skip to content

Instantly share code, notes, and snippets.

@isu3ru
Created September 24, 2017 13:00
Show Gist options
  • Save isu3ru/1de10d40a75811dd8e4b71947f5b9006 to your computer and use it in GitHub Desktop.
Save isu3ru/1de10d40a75811dd8e4b71947f5b9006 to your computer and use it in GitHub Desktop.
<?php
function setFlashDataItem($key, $value)
{
if (!array_key_exists('flashdata', $_SESSION)) {
$_SESSION["flashdata"] = array();
}
$_SESSION["flashdata"][$key] = $value;
}
function removeFlashDataItem($key)
{
if (!array_key_exists('flashdata', $_SESSION)) {
return FALSE;
}
if (array_key_exists($key, $_SESSION["flashdata"])) {
unset($_SESSION["flashdata"][$key]);
}
}
function clearFlashData()
{
//removing the outer element removes all flash data key-value pairs inside the array
$_SESSION["flashdata"] = array();
}
function hasFlashDataItem($key)
{
if (!array_key_exists('flashdata', $_SESSION)) {
return FALSE;
}
return array_key_exists($key, $_SESSION["flashdata"]);
}
function getFlashDataItem($key)
{
if (!array_key_exists('flashdata', $_SESSION)) {
return FALSE;
}
return array_key_exists($key, $_SESSION["flashdata"]) ? $_SESSION["flashdata"][$key] : FALSE;
}
function getFlashData()
{
if (!array_key_exists('flashdata', $_SESSION)) {
return FALSE;
}
return $_SESSION["flashdata"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment