It allows us to manage unique users across requests and also helps to stores data for specific users. We can access session from controllers, views, helpers, cells, and components.

We can use session in cakePHP in following ways :-

 

How to create session?

We can use the write() to create or write session.
Example : $session->write('username', 'bestinterviewquestion.com');

 

How to read session?

We can use the read() to get stored data from session.
Example : $session->read('username');

 

How to Check session?

We can use the check() to check this data is exists or not in session.
Example :

if ($session->check('username')) {
  // name exists and is not null.
}

 

How to delete session?

We can use the delete() to delete data from session.
Example : $session->delete('username');

 

How to destroy session?

We can use the destroy() to destroy session.
Example : $session->destroy();

BY Best Interview Question ON 13 Jan 2019