Location: PHPKode > projects > Yupi cms > yupi-cms/include/class.yc_session.php
<?php
/**
 * @author Edin.o
 * @copyright 2009
 */
/*
PHP session handling wraped into nice class
Use Destroy to destroy session when you don't need it
*/
class Yc_Session
{
    #Instance for this class
    private static $instance;

    private function __construct()
    {
        #start or continue session
        session_start();
    }

    #Get session instacea
    public static function getInstance()
    {
        if (!isset(self::$instance))
        {
            self::$instance = new Yc_Session();
        }
        return self::$instance;
    }

    #Set session value
    function Set($key, $value)
    {
        $_SESSION[$key] = $value;
    }

    #Set flash data to session, using GetFlash function this value is removed from session
    function SetFlash($key, $value)
    {
        $key = "f:$key";
        $_SESSION[$key] = $value;
    }

    #Read and remove data from session set by setFlash function
    function GetFlash($key, $remove = true, $def = null)
    {
        $key = "f:$key";
        $val = $_SESSION[$key];
        if (!isset($val))
        {
            $val = $def;
        }
        if ($remove)
            unset($_SESSION[$key]);

        return $val;
    }

    #Get value from session
    function Get($key, $def = null)
    {
        if (isset($_SESSION[$key]))
        {
            return $_SESSION[$key];
        }
        else
        {
            return $def;
        }
    }

    #Delete session data
    function Delete($key)
    {
        unset($_SESSION[$key]);
    }


    #Destroy session data
    function Destroy()
    {
        session_destroy();
    }
}
?>
Return current item: Yupi cms