You are here: Home / Topics / What is a session in PHP?

What is a session in PHP?

Filed under: PHP on 2022-10-08 08:34:46

A session in PHP is a way to store information to be used across multiple pages of an entire website. The information is not stored on the user’s computer, unlike cookies. In a temporary directory on the server, a file will be created by the session where registered session variables and their values are stored. This information will be available to all pages on the site during that visit.

When you work with an application, you open it, do some modifications, and then you close it. This is much like a Session. The computer knows who you are. It knows when the application is started and ended by you.

But on the internet, the webserver does not know who you are or what you do, because the HTTP address doesn’t maintain a state. This problem is solved using session variables by storing user information to be used across multiple pages (e.g. username, favorite color, etc).

By default, session variables will last until the user closes the browser.

So Session variables hold single user information and are available to all pages in one application.

 

We can manually set the sessions for users. Like when any user log in to our website we usually create session for example.

$_SESSION['LOGGED_IN']=true;

This session will be used to verify whether the user is logged in or not. 

About Author:
S
Shivam     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.