Posted On: Nov 17, 2022
PHP Sessions allows you to identify unique users across requests and store persistent data for specific users against a unique session ID. This can be used to persist state information between page requests. Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data.
You can access the session data any place you have access to a request object. This means the session is accessible from:
In addition to the basic session object, you can also use the Cake\View\Helper\SessionHelper to interact with the session in your views. A basic example of session usage would be:
$name = $this->request->session()->read('User.name'); // If you are accessing the session multiple times, // you will probably want a local variable. $session = $this->request->session(); $name = $session->read('User.name');
Session::read($key) function is used to read specific session data in CakePHP.
Session::write($key, $value) function is used to write session data in CakePHP.
Session::delete($key) function is used to delete specific session data in CakePHP.
Sample Usage
//Reading a session $session->read('Config.language'); //Writing a session $session->write('Config.language', 'en'); //Deleting a session $session->delete('Some.value');
Never Miss an Articles from us.
CakePHP is an open-source free web framework written in PHP scripting Language for rapid web development...
How to get current URL in CakePHP ?..
MVC stands for the model view controller.MVC is not a design pattern, it is an architectural pattern that describes a way to structure our application and explains the responsibilities and interaction..