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; ahref & qu 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.