Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

96 lines (76 sloc) 1.394 kb
<?php
class Session
{
public static function start()
{
if (defined('SESSION_NAME'))
{
session_name(SESSION_NAME);
}
session_start();
}
public static function read($key)
{
global $_SESSION;
$key_bits = explode(".", $key);
$cursor = $_SESSION;
foreach ($key_bits as $bit)
{
if (isset($cursor[$bit]))
{
$cursor = $cursor[$bit];
}
else
{
return false;
}
}
return $cursor;
}
public static function get($key)
{
return self::read($key);
}
public static function write($key, $value)
{
global $_SESSION;
$key_bits = array_reverse(explode(".", $key));
$new_vals = $value;
foreach ($key_bits as $bit)
{
$new_vals = array($bit => $value);
}
$_SESSION = array_merge($_SESSION, $new_vals);
}
public static function set($key, $value)
{
return self::write($key, $value);
}
public static function delete($key)
{
unset($_SESSION[$key]);
return;
}
public static function destroy()
{
$_SESSION = array();
session_destroy();
}
public static function set_flash($msg, $type = 'normal')
{
self::write('flash_message', array('msg' => $msg, 'type' => $type));
}
public static function get_flash()
{
if (self::read('flash_message'))
{
$msg = self::read('flash_message');
self::delete('flash_message');
return $msg;
}
else
{
return false;
}
}
}
Jump to Line
Something went wrong with that request. Please try again.