Sessions are a set of variables that are stored on the server. To start a session, you need to call the session_start() function.
The session allows you to save the state between different requests and interact with the user over several pages.
It must be called before the response is sent to the user:
session_start();//start the session before the call $_SESSION['login'] = 'admin';//create a new element of the array
You can refer to a variable to handle this data $_SESSION
echo $_SESSION['login'];
To operate on the data of a variable on other page it is necessary to start session:
session_start();
To remove an array element from a session, use the unset() function
unset($_SESSION['login']);
Get the session ID
php session_start(); echo session_id(); // session ID echo session_name(); // session name
You can delete all session data using the session_destroy() function:
session_start(); session_destroy()
Note that to use $_SESSION, you must call session_start() at the beginning of every script that uses a session. This allows PHP to establish or restore a session for the current user.