Get acquainted with the PHP session

Source: Internet
Author: User
Tags php session php script

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.