In PHP, a session provides a way to save the preferences of visitors to a web page on a web server in the form of variables that can be used on multiple pages.


Suppose we have a two pages one page to store session another to access the session is available on every pages of your website in PHP

  1. index.php
  2. access.php

Start session

Whenever you need to use a session first thing we need to start session then we can do operation on a session


index.php

<?php

session_start();
$_SESSION['data'] = "my session data";


How to access session data?

We had store data on index.php file now we will access that session in aoother page which is access.php


access.php

<?php

session_start();
echo $_SESSION['data'];


output:

my session data