Several complementary functions of the session are discussed much in PHP. In fact, we have not noticed several functions in PHP4. Let me introduce them to you. Session_set_save_handler () is really a good thing. // ********************* Session_unset (PHP44.0b4) v supplementary functions on the session
In PHP, there are a lot of discussions about Sessions. In fact, there are still several functions in PHP4 that we have not noticed at ordinary times.
Let me introduce them to you.
Session_set_save_handler () is really a good thing.
This function only applies to the current script file.
//*******************************
The function to be introduced below should be very useful to everyone. are you interested in customizing a session to save without cookies? This function can achieve your assumption.
Let me think about the benefits of using cookies? At least, you don't have to worry about whether the client's cookie function is enabled, right.
This function can define user-level session storage functions (open, close, write, etc ).
For example, this function is useful when we want to save the session in a local database.
!! Note: Before using this function, configure the php. ini file and session. save_hadler = user. otherwise, session_set_save_handler () will not take effect.
In addition, according to my tests, if you want this session to be used across pages, you must add your custom function and session_set_save_handler to each session script file. therefore, the best way is to make a separate file and include it in every session script.
The following example provides a basic session persistence method, similar to the default files method.
If you want to use a database, this is also easy to implement.
Example 1. session_set_save_handler () example
Function open ($ save_path, $ session_name ){
Global $ sess_save_path, $ sess_session_name;
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