The following should be appended to the end of
the library defined in Listing 18-2:
session_set_save_handler("mysql_session_open", "mysql_session_close",
"mysql_session_select",
"mysql_session_write",
"mysql_session_destroy",
"mysql_session_garbage_collect");
To test the custom handler implementation, start a session and register a session
variable using the following script:
INCLUDE "mysqlsessionhandlers.php";
session_start();
$_SESSION['name'] = "Jason";
?>
After executing this script, take a look at the sessioninfo table??™s contents using the
mysql client:
CHAPTER 18 ?– SESSION HANDLERS 469
mysql> select * from sessioninfo;
+---------------------------------------+-------------------+-------------------
+
| SID | expiration | value |
+---------------------------------------+-------------------+-------------------
+
| f3c57873f2f0654fe7d09e15a0554f08 | 1068488659 | name|s:5:"Jason"; |
+---------------------------------------+-------------------+-------------------
+
1 row in set (0.00 sec)
As expected, a row has been inserted, mapping the SID to the session variable
"Jason". This information is set to expire 1,440 seconds after it was created; this value
is calculated by determining the current number of seconds after the Unix epoch,
and adding 1,440 to it. Note that although 1,440 is the default expiration setting as
defined in the php.
Pages:
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549