Php session familiarity

Source: Internet
Author: User
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, "/");

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: info-contact@alibabacloud.com 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.