Concept Understanding:
The session in the Web mainly refers to the user browsing a site, from entering the site to close this site through the time.
Working principle:
1. Start the seesion, the server will pass to the browser a unique identity with a key value of PHPSESSID is stored in a local cookie, and a corresponding session file is generated according to the key value in the corresponding directory
After setting the session value, the value exists in the session file
2. The server PHP script reads the session value, the browser returns the unique identifier of the key value, by starting the session, and then according to the key value can be loaded from the session file stored variables
3. When the PHP script executes, the non-destroyed session variable is automatically saved in a session file that is uniquely identified under a local path, and the path can be set through the Session.save_path in the php.ini
1. Set session value, start session first, then set
Session_Start (); $_session[' name '] = ' wyz ';
2. Read Session value
Session_Start (); Echo $_session[' name '];
3. Delete Session
A. For a single
unset ($_session[' name ');
B. For all
Session_destroy ();
4. Set the session's unique identity value Cookie's retention time on the browser, or set the time at which the session value will be stored
Session_Start (); $_session[' name '] = ' wyzss '; $lifeTime = 3600;setcookie (Session_name (), session_id (), time () + $lifeTime, "/");
Note: Setting the Gc_maxlifetime under PHP.ini can only guarantee the shortest time for the session to survive.
Get acquainted with the PHP session