PHP Sessions

PHP Sessions stores information across the various pages of a website. A file gets created in a temporary directory on the server. In the file, registered session variables and values get stored. In this lesson, we will see how to:

  • Start a session in PHP
  • Delete a session in PHP

Start a session

We will learn how to start a session. The method session_start() starts a session and the isset() function checks if the session variable is set or not.

Let us now see an example to start a session in PHP:

Here’s the output,

PHP Sessions

Destroy a session

Create as well as destroy PHP sessions with ease. With PHP, easily delete all the sessions and session variables. For that, we will be using the following two methods,

  • session_unset( ): to remove session variables,
  • session_destroy(): destroys the session

Let us see an example to destroy a session:

PHP Cookies
PHP require Statement
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading