How to Start, Get and Modify a Session

How to Start, Get and Modify a Session

In this tutorial, we will try to explore How to Start, Get and Modify a Session.

What is a Session?

When you run an application, do some work on it and then you close it. This is like a session. When you start an application the computer knows that it’s you who is using it. But on the internet, the web servers don’t know who you are. So they store user’s information by using a session variable.

How to Start a PHP session?

We can start a PHP session by using the following function:

session_start();

We use PHP global variables to set session variables.

Example:

Get Values from Session Variables

Lets see the code of “Get Values from Session Variables”.

Modifying a PHP Session Variable

Let’s see the code of “Modifying a PHP Session Variable”.

Delete PHP Session

To delete/destroy php session variables, we use “session_unset()” and “session_destroy()”:

Example:

Add a Comment