Special welcome gift. Get 50% off your first courses with code “AS50”. Find out more!

HomeInterviewWhat is a Session in PHP? How does PHP manage the lifecycle of a session?
courses 19

What is a Session in PHP? How does PHP manage the lifecycle of a session?

Sessions are data structures that provide a way to store user-specific data and associate it with a unique session ID. However, PHP sessions also solve the following problems.

A session creates a file in a temporary directory on the server to cache the registered session variables and their values. This data will be accessible to all pages on the site during that stay.

PHP uses a php.ini file to get hold of the server settings. This file also specifies the location of the session file under the <session.save_path>. The developers can make sure that this setting points to a correct value before using the session variable.

PHP Session Lifecycle.

php interview questions - lifecycle of php session

While building up a session following events happen.

1. PHP generates PHPSESSID such as “c69dc153f003406b9a0242ad4c505baa”.

2. The PHP engine creates a file for every new session at the designated location. It bears the name of the unique identifier prefixed by <sess_>.

e.g. sess_c69dc153f003406b9a0242ad4c505baa.

3. When PHP gets a request from the browser or a client to access the session variable, it retrieves the session string from the PHPSESSID cookie.

4. A session comes to an end if the user decides to close the browser. However, the server could also terminate it after a certain inactivity period.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

Categories

ads sidebar 1

You May Also Like

Oracle has several modes for shutting down the database: In normal mode, the database is shut down by default. It...
Materialized views are items that contain condensed sets of data from base tables that have been summarized, clustered, or aggregated. They...
Every database in Oracle has a tablespace called SYSTEM, which is generated automatically when the database is created. It also...