How to process session in MongoDB in PHP

Source: Internet
Author: User

Cookie is only a way for the session to bind the client. Other methods such as session_set_save_handler, such as URL, are only the storage method for the server and session. The default method is file storage, which can be changed to any other storage, such as databases and memcache
You can use the session_set_save_handler function:
Bool session_set_save_handler (callback $ open, callback $ close,
Callback $ read, callback $ write,
Callback $ destroy, callback $ GC)
Note: before using this function, configure the php. ini file and session. save_hadler = user. Otherwise, session_set_save_handler () will not take effect.

The first parameter is the processor called when the session is opened. The two parameters save_path and session_name are accepted, respectively, as the session storage path (remember that the default mechanism of PHP is file mode, so there is a file path) and the key name used to save the session ID in the cookie. The key name can be obtained and modified through session_name.

The second parameter is the processor when the session is closed, and there is no Parameter

The third parameter is the processor used to read the session. It accepts the session_id parameter, representing the session ID saved in the cookie.

The fourth parameter is the processor used to save the session. It accepts two parameters: session_id and session_data. As mentioned in the official manual, after PHP 5.0.5, the close and write processors will be called after the class structure, so classes and throws exceptions cannot be used in the processor (exception is also a class) the session can be used in the destructor, so we needProgramTo ensure that session_write_close is completed before the destructor.

Register_shutdown_function ('session _ write_close ');

The fifth parameter is the processor used to delete a session. The parameter session_id is used to represent the session ID saved in the cookie.

The last parameter is the processor when the session expires. The parameter maxlifetime is used to indicate the number of timeout seconds.

Related Article

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.