Figure 18-1. Tracking a user??™s viewed documents
Creating Custom Session Handlers
User-defined session handlers offer the greatest degree of flexibility of the four storage
methods. Implementing custom session handlers is surprisingly easy, done by following
just a few steps. To begin, you??™ll need to tailor six tasks (defined below) for use with
your custom storage location. Additionally, parameter definitions for each function
CHAPTER 18 ?– SESSION HANDLERS 463
must be followed, again regardless of whether your particular implementation uses
the parameter. This section outlines the purpose and structure of these six functions.
In addition, it introduces session_set_save_handler(), the function used to magically
transform PHP??™s session-handler behavior into that defined by your custom handler
functions. Finally, this section concludes with a demonstration of this great feature,
offering a MySQL-based implementation. You can immediately incorporate this
library into your own applications, using a MySQL table as the primary storage location
for your session information.
session_open($session_save_path, $session_name): This function initializes any
elements that may be used throughout the session process. The two input
parameters $session_save_path and $session_name refer to the namesake configuration
directives found in the php.ini file. PHP??™s get_cfg_var() function is used to
retrieve these configuration values in later examples.
Pages:
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544