Php session familiarity
Concepts:
Session on the web refers to the period from when a user browses a website, from when the user enters the website to when the website is closed.
Working principle:
1. when seesion is started, the server will pass the browser a unique identifier with the PHPSESSID key value stored in the local cookie, and a corresponding session file will be generated under the corresponding directory of the server based on the key value
After the session value is set, the value exists in the session file.
2. if the server php script reads the session value, the browser returns the unique identifier of the key value. by starting the session, the browser can then load the stored variables from the session repository according to the key value.
3. when php script execution ends, session variables that are not destroyed will be automatically stored in the session file uniquely identified in a local path. session in ini. save_path settings
1. set the session value. start the session first, and then set
session_start();$_SESSION['name'] = 'wyz';
2. read the session value
session_start();echo $_SESSION['name'];
3. delete a session
A. for a single
unset($_SESSION['name']);
B. for all
session_destroy();
4. set the unique identifier value of the session. the cookie retention time in the browser can also be said to set the time for storing the session value.
session_start(); $_SESSION['name'] = 'wyzss';$lifeTime = 24 * 3600;setcookie(session_name(), session_id(), time() + $lifeTime, "/");