Session_set_save_handler ()

Source: Internet
Author: User
In session_set_save_handler (), I write the SESSION to the database, and the sessionID is passed through URL. A. php: PHPcode & lt ;? Phprequire (session. php); session_start (); $ _ SESSION [test] 1; echo & lt; a session_set_save_handler ()
I write the SESSION to the database, and the sessionID is passed through the URL.

A. php:
PHP code
  
  


B. php
PHP code
  
  


Session. php:
PHP code
  
  {$ Time} "; $ result = mysql_query ($ SQL, $ link); if (@ $ row = mysql_fetch_row ($ result, $ link )) {return $ row [0];} else {return '';} function write ($ sessionId, $ sessionData) {global $ link, $ expiry; $ sessionId = mysql_escape_string ($ sessionId); $ sessionData = mysql_escape_string ($ sessionData); $ time = time () + $ expiry; $ SQL = "INSERT INTO session (session_id, value, expiry) VALUES ('{$ sessionId}', '{$ sessionData}', {$ time}); "; $ result = mysql_query ($ SQL, $ link ); if ($ result) {return true;} $ SQL = "UPDATE session SET value = '{$ sessionData }', expiry = {$ time} WHERE session_id = '{$ sessionId}' "; $ result = mysql_query ($ SQL, $ link ); if ($ result & mysql_affected_rows ($ link) {return true;} else {return false ;}} function destroy ($ sessionId) {global $ link; $ sessionId = mysql_escape_string ($ sessionId); $ SQL = "delete from session WHERE session_id = '{$ sessionId}';"; $ result = mysql_query ($ SQL, $ link ); if ($ result) {return true;} else {return false;} function gc ($ maxLifeTime) {return true ;}



This is the case now:
Run a. php and the SESSION is saved to the database:
+ ---------------------------- + ---------------------------------- + ------------ +
| Session_id | value | expiry |
+ ---------------------------- + ---------------------------------- + ------------ +
| O7olki3vma7k8bakhk71emco6 | isLogin | I: 1; permission | s: 0: ""; | 1344495859 |
+ ---------------------------- + ---------------------------------- + ------------ +

The problem is:
When you click the hyperlink of a. php to go to B. php, the SESSION value represented by the passed sessionID is cleared.
+ ---------------------------- + ------- + ------------ +
| Session_id | value | expiry |
+ ---------------------------- + ------- + ------------ +
| O7olki3vma7k8bakhk71emco6 | 1344496029 |
+ ---------------------------- + ------- + ------------ +

Later I found that when I ran the B. php page, I executed the UPDATE in the write () method:
UPDATE session SET value = '', expiry = 1344496029 WHERE session_id = 'o7olki3vma7k8bakhk71emco6'
But I have not changed the SESSION operation on the B. php page? What's going on?

Thank you !!!


------ Solution --------------------
Php does not know whether you have modified the value of the session variable.
So he always needs to rewrite the session back.

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.