Open In App

What is a session and how to start a session in PHP?

A session in PHP is a way to preserve data across subsequent HTTP requests. It allows information like user authentication status or user preferences to be stored and accessed throughout a user’s interaction with a website.

Starting a Session:

To start a session in PHP, use the session_start() function at the beginning of your PHP script. This function initializes a session or resumes the current one if it already exists.

<?php
session_start();
// Session started
?>

Destroying Complete Session

The session_destroy() function is used to destroy a session. The session_destroy() function does not require any argument.

<?php 
// session started
session_start( );        
// session destroyed session_destroy( ); ?>

Important Points:

Article Tags :