Advanced application of Session in PHP

Source: Internet
Author: User

Save the session to a location of your own definition

How to share folders under 1.Linux using NFS or Samba

2. Save with Database

3. Save to Memcache

The workaround is to---> Session_set_save_handler ("Open", "close", "read", "write", "Destroy", "GC");

Second, about the session in PHP configuration items:

1//Simple property setting for session2     3Session.name = Phpsessid//name of the SessionID4Session.auto_start = 0//whether the session is automatically opened in the script, i.e. session_start (); Default 0 does not open5Session.save_path = "C:/wamp/tmp"//the path to the session file save6 7Session.use_trans_sid = 0//When a cookie is blocked on the browser side, all linked forms in the script are automatically added with parameters SessionID8 9//cookie Settings in sessionTen  OneSession.use_cookies = 1//is the first cookie saved SessionID ASession.cookie_path =///Where cookies are saved on the browser -Session.cookie_domain = -Session.cookie_lifetime = 0//saves the session's cookie lifetime on the browser, 0 means it is invalid when exiting the browser the  -//Save session information to database or Memcache -  -Session.save_handler = Files//session saved in the form of a text file or database--user memcache--memcache +Session.save_path = "C:/wamp/tmp"//when put to memcache, change to FTP form -  +Using functions:Session_set_save_handler("Open", "close", "read", "write", "Destroy", "GC"); A  at//garbage Collection at session -     //session garbage collection interval, after how many seconds after the useless session is considered garbage removal. That is, how many seconds after the user no longer sends the request, the session becomes garbage. -Session.gc_maxlifetime = 1440 -     //the garbage collection mechanism of the session: When the script executes Session_Start (), the probability of garbage collection occurring is: session.gc_probability/session.gc_divisor:1/1000 Note that when the site has a lot of users accessing the situation -session.gc_probability = 1 -Session.gc_divisor = 1000

Third, configure the session

1. Change the location of the session file on the server

Change Session.save_path = "c:/wamp/tmp"-Specify Site Directory

2. Set the validity period of SessionID on the browser

Session.cookie_lifetime = 0//Invalid session when closing browser

Session.cookie_lifetime = 3600*24//session valid for one day

Session.cookie_lifetime = 3600*24*7 The session is valid within//7 days

Note: You should also change the duration of the session on the server side, session.gc_maxlifetime = 3600*24*7

  3. Place the session in the database

Session.save_handler = user

4. Place the session in the Memcache

Session.save_handler = Memcache

  

Advanced application of Session in PHP

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.