What is session sharing?

What is session sharing?


I'll try to explain this briefly using PHP as a programming language.

Session sharing is a way of passing and/or storing information between files/pages. It has a lot of advantages.

It is actually an array in PHP, $_SESSION is where the key-value pairs are stored.



To start using this you start the session, store the values and end the session when needed. You can pass important details such as session id and or other data between files. Every session has an ID attribute associated with it which identifies the current session.

Multiple requests are easily handled when you use sessions. The state of the session is available till it's destroyed.

Below is a very simple example to store the current user who is logged in. The variable is accessible till the session is destroyed.

<?php
// start a session
session_start(); //Starts the session
 
// initialize a session variable
$_SESSION['current_user'] = '0x00username';
 
// unset a session variable
unset($_SESSION['logged_in_user_id']); //Ends the session
?>

That's a very basic example and explanation of sessions. If you have a specific doubt, please clarify in the comment section. I'll try to answer.

Post a Comment

0 Comments

React