What Is a Session IN PHP

What is a session? How does the session work In PHP?

Its a Global variable to be used across multiple pages for authenticating a particular user.



It creates a 32-digit hexadecimal string named PHPSESSID  in  Server. When the User navigates the page it will match this ID with the Session ID to recognize the same user.

Session variables are stored in an associative array called $_SESSION[].

Start the session

 



Set Session variable

 

Remove all session variables

 

Here is the example to unset a single variable 

 



Here is the call which will destroy all the session variables 

 

The default session time in PHP is 24 minutes (1440 seconds).
We can change the time in php.ini

 

Or



In PHP file you can do the below like

 

Questions Asked in Interview About Session In PHP

  1. What is Session
  2. How to store a variable in Session
  3. How to destroy Session
  4. What is the default time for a session

 



Tags: , , ,