Sessions

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,

  • A unique ID is generated for that particular session.
  • A cookie is sent to the client side.
  • All these session variables are saved in the temporary folder on the server.
  • When a value is retrived from the session variable, it automatically gets unique session ID from the cookie. Then it looks into its temporary folder for the particular file.

# 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.