Skip to content

Session

Stefano Azzolini edited this page Aug 27, 2014 · 1 revision

The Session module allow you to make hashes of variables.

Create a new session

Start the session handler with the Session::start method.

Session::start();

You can pass a custom SID string as parameter.

Session::start("AWESOME_APP_SID");

Close and clear session

All saved data and the session can be deleted with the Session::clear method.

Session::clear();

Retrieve a session value

You can retrieve a value from session stash via the Session::get method. An optional second parameter can be passed for a default value if the requested one is missing.

$mydata = Session::get('mydata',"some default data");

Set a session value

You can set a value into session stash via the Session::set method.

$mydata = Session::get('my_options',[
  'a' => 1,
  'b' => 2,
]);

$mydata['a']++;

print_r( Session::set('my_options',$mydata) );

First run

Array
(
    [a] => 1
    [b] => 2
)

Second run

Array
(
    [a] => 2
    [b] => 2
)

Check if a key is in session stash

You can check if a variable is in session stash with the Session::exists method.

if(!Session::exists('user')) Redirect::to('/login');
Clone this wiki locally