Sessions allow us to get access to data across various pages for each user request. A file is created in a temporary directory on the server by session to store all session variables. This stored data is available to all the pages of a web site during the visit of a particular user.
In PHP, session is accessed through the $_SESSION global variable.
When a session starts,
Sessions Opening and Closing
Let's see an example of opening and closing a session.
Step 1 Go to the SiteController.php file. Add the action actionCheckStatus.
Look at the above code, it shows session opening, session closing, checks whether session is active or not and destroys the session.
Step 2 Run it on the browser with the URL,
Accessing Session Data
During accessing of the data, if no session is running than session will automatically start it.
To access the data stored in the session, run the following code.