Loading, please wait...

ARTDESIGN FRAMEWORK

SESSION

Description

ArtDesign FrameWork Session - Session Management - choice between Native Sessions and DataBase Sessions

Implementation

//01. Create MySql Table - if you use DataBase Session
CREATE TABLE IF NOT EXISTS `Sessions` (
  `ID` varchar(32) NOT NULL,
  `Data` text NOT NULL,
  `ValidUntil` int(11) NOT NULL,
  UNIQUE KEY `ID` (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


//02. SetUp DataBase Settings - /Path/To/ArtDesign/PHP/Settings/DataBase.php
$ConfigurationData = array(
    "SQLDefault" => array(
        "SQLType" => "mysql",
        "SQLHost" => "localhost",
        "SQLDataBase" => "data_base_name",
        "SQLUser" => "mysql_user",
        "SQLPassword" => "mysql_password",
        "SQLPDO" => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        )
    )
);
return $ConfigurationData;


//03. SetUp Session Settings - /Path/To/ArtDesign/PHP/Settings/Session.php
$ConfigurationData = array(
    "SessionDefault" => array(
        "AutoStart" => 1,
        "Type" => "DataBase", //DataBase, Native
        "Name" => "__ADUISession",
        "LifeTime" => 60*60,
        "Path" => "/",
        "Domain" => "",
        "Secure" => 0,
        "DataBaseConnection" => "SQLDefault",
        "DataBaseTable" => "Sessions"
    )
);
return $ConfigurationData;

How it works

ArtDesign FrameWork Session automatically updates the session time at every page reloading.

Adding data to the session

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$Session = $ArtDesign->GetSession();
$Session->NameOfData = array(
    "Key" => "Value"
);
$ArtDesign->SaveSession();

Removing data from the session

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$Session = $ArtDesign->GetSession();
$Session->UnsetSessionElement("NameOfData");
$ArtDesign->SaveSession();

Read data from the session

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$NameOfData = $ArtDesign->GetSession()->NameOfData;
print_r($NameOfData);
/*
    return array
    Array ( [Key] => Value )
*/