Prev | Current Page 534 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

Keep in mind that these names could be anything you
choose, but they must accept the proper number and type of parameters, as specified
in the previous section, and must be passed into the session_set_save_
handler() function in this order: open, close, read, write, destroy, and garbage collect.
An example depicting how this function is called follows:
session_set_save_handler("session_open", "session_close", "session_read",
"session_write", "session_destroy",
"session_garbage_collect");
The next section shows you how to create handlers that manage session information
within a MySQL database.
Using Custom MySQL-Based Session Handlers
You must complete two tasks before you can deploy the MySQL-based handlers:
1. Create a database and table that will be used to store the session data.
2. Create the six custom handler functions.
The following MySQL table, sessioninfo, will be used to store the session data. For
the purposes of this example, assume that this table is found in the database sessions,
although you could place this table where you wish.
CREATE TABLE sessioninfo (
SID CHAR(32) NOT NULL,
expiration INT NOT NULL,
value TEXT NOT NULL,
PRIMARY KEY(SID)
);
Listing 18-2 provides the custom MySQL session functions. Note that it defines
each of the requisite handlers, making sure that the appropriate number of parameters
is passed into each, regardless of whether those parameters are actually used in
the function.


Pages:
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546