Sessions

Introduction

A session is a way to store information (in variables) to be used across multiple pages.

Unlike a cookie, the information is not stored on the users computer.

Assign the value

To add a value to an existing key or create it if it does not exist and assign the value to it.

Session::set("name", "Hassan");

and You can change key name of variable.

Session::name("website", "url");

You can use flash session to remove key after showing it once.

Session::flash("name");

Check key

To check if a key exists, it returns true, and if it doesn't, it returns false.

Session::has("app", "name");

Get value

Get value of key.

Session::get("app", "name");

You can set a default value when the key is not present.

Session::get("app", "name", "Hassan");

and you can get all keys using all() method.

Session::all();

Delete keys

You can delete the key using delete() method.

Session::delete("name");

You can delete all the keys use destroy() method.

Session::destroy();

Last updated