How to configure Session in php

Source: Internet
Author: User
In the history of Web technology development, although the emergence of Cookie technology is a major change, the Cookie is actually stored in the client's computer, so it has caused a controversy: Users have the right to prevent Cookie use, this prevents Web servers from tracking user information through cookies. In the history of Web technology development, although the emergence of Cookie technology is a major change, the Cookie is actually stored in the client's computer, so it has caused a controversy: Users have the right to prevent Cookie use, this prevents Web servers from tracking user information through cookies. The Session technology stores user-related data in the server system, so users cannot stop using the Session.

Cookie can be compared to the shopping membership card that the merchant handles for the customer when going to the mall for the first time and is saved by the customer. If the customer forgets to carry the shopping card when they go to the Mall next time, or loses the shopping card, the user cannot use the membership to shop again. However, if the seller has completed the membership card for the customer and the mall saves the member card, the user does not need to put the card on himself. However, there are a lot of customers who apply for membership cards in the mall. when customers come to the mall every time, how can they know whether they are members of the mall? When the customer comes to the mall to apply for a membership card, the mall will ask to save the card number of the member card in the customer's class. when the customer comes to the mall for purchase next time, the mall can query the registration and consumption information of the membership card through the customer's card number.

In this case, the client only needs to save a Session identifier (equivalent to the card number of the membership card) created by the server for the user.

Session ID, while the Session variable value is saved on the server side (File/database. Session ID is a regular string consisting of 32-bit hexadecimal numbers that is neither repeated nor easily found. The Session ID is saved in the Cookie of the client. if the user blocks the use of the Cookie, the Session ID can be saved in the URL in the address bar of the user's browser.

The php configuration file contains a set of Session-related configuration options. You can configure the Session by setting some options. Otherwise, the default Session configuration will be used.

Php. ini settings reference:

1. session access mode

Session. save_handler = files

2. session file storage path

Session. save_path =/tmp

3. the session uses the cookie function to start: 1

Session. use_cookies = 1

4. session name

Session. name = PHPSESSID

5. automatic start; 0: Off; 1: enabled

Session. auto_start = 0

6. session cookie lifetime, in seconds

Session. cookie_lifetime = 0

7. valid cookie domain name

Session. cookie_domain = "a.com"

8. the probability is session. gc_probability/session. gc_pisor result 1/1000. it is not recommended to set too small because the session garbage collection requires checking whether each file has expired.

Session. gc_probability = 1

Session. gc_pisor = 1000

9. the default expiration time is 24 minutes.

Session. gc_maxlife time = 1440

The above describes how to configure the Session in php. For more information, see other related articles in the first PHP community!

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.