Phpsession custom processing-PHP source code

Source: Internet
Author: User
PHP session custom processing PHP code

Session. gc_probability = 1 // The default value is 1. the larger the value, the better session. gc_pisor = 100 // The default value is 100. the smaller the value, the better. // The default value is one hundred requests for one gc call. Session. gc_probability is equivalent to the numerator, and session. gc_pisor is equivalent to the denominator. If you want to change gc to the same one every time, you can use session. gc_maxlifetime = 30 // session survival time
 ". Time (); $ result = mysql_query ($ query); if (mysql_num_rows ($ result) {$ row = mysql_fetch_assoc ($ result ); $ value = $ row ['value']; return $ value;} else {return false ;}} function session_write ($ SID, $ value) {$ lifetime = get_cfg_var ("session. gc_maxlifetime "); $ expiration = time () + $ lifetime; $ query =" insert into session VALUES ('$ SID', '$ expiration', '$ value ')"; $ result = mysql_query ($ query ); If (! $ Result) {$ query = "UPDATE session SET expiration = '$ expiration', value = '$ value' where sid =' $ SID 'AND expiration> ". time (); $ result = mysql_query ($ query) ;}} function sessionDestroy ($ SID) {$ query = "delete from session where sid = '$ SID '"; $ result = mysql_query ($ query);} function session_gc () {$ query = "delete from session WHERE expiration <". time (); $ result = mysql_query ($ query); echo m Sessions ();} session_set_save_handler ("session_open", "session_close", "session_read", "session_write", "sessionDestroy", "session_gc"); session_start ();?>

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.