Mecha CMS

Mecha CMS blog and documentation.

Class Session

Updated: Sunday, 07 August 2016

Session handling.

Sessions

Set Session

echo Session::set('foo', 'bar');

Get Session

echo Session::get('foo');

The code above will outputs “bar”.

Remove Session

Session::kill('foo');

Ability to handle multidimensional array added since version 1.0.2 via Mecha::SVR, Mecha::GVR and Mecha::UVR.

Set Session Recursively

Session::set('foo.bar', 'baz');

Get Session Recursively

echo Session::get('foo.bar');

Remove Session Recursively

Session::kill('foo.bar');

Get All Sessions

var_dump(Session::get());

Remove All Sessions

Session::kill();

Cookies

Ability to handle cookies added since version 1.1.1. Use it by adding a prefix cookie: before the session name.

Session::set('cookie:foo', 'bar', 1); // Expired in 1 day

Session::set('cookie:baz', array(
    'test_1' => 'Hello!',
    'test_2' => true,
    'test_3' => 5000
), 1);
echo Session::get('cookie:foo');

The code above will outputs “bar”.

Session::kill('cookie:foo');
Session::set('cookie:baz.test_1', 'Bye!', 1);
echo Session::get('cookie:baz.test_1');
Session::kill('cookie:baz.test_1');

Get All Cookies

var_dump(Session::get('cookies'));

Remove All Cookies

Session::kill('cookies');
Donation and Email Subscription