11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 18 • SESSION HANDLERS// Output list of requested articles?>echo "Recently Viewed Articles";echo "";foreach($_SESSION['articles'] as $doc) {echo "$doc";}echo "";The sample output is shown in Figure 18-1.Figure 18-1. Tracking a user’s viewed documentsCreating Custom Session HandlersUser-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. Tobegin, you’ll need to tailor six tasks (defined below) for use with your custom storage location.Additionally, parameter definitions for each function must be followed, again regardless of whether yourparticular implementation uses the parameter. This section outlines the purpose and structure of thesesix functions. In addition, it introduces session_set_save_handler(), the function used to magicallytransform <strong>PHP</strong>’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 <strong>MySQL</strong>-basedimplementation. You can immediately incorporate this library into your own applications, using a<strong>MySQL</strong> table as the primary storage location for your session information.• session_open($session_save_path, $session_name): This function initializesany elements that may be used throughout the session process. The two inputparameters $session_save_path and $session_name refer to the namesakeconfiguration directives found in the php.ini file. <strong>PHP</strong>’s get_cfg_var()function is used to retrieve these configuration values in later examples.• session_close(): This function operates much like a typical handler functiondoes, closing any open resources initialized by session_open(). As you cansee, there are no input parameters for this function. Keep in mind that thisdoes not destroy the session. That is the job of session_destroy(),introduced at the end of this list.381

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!