note 58390 added to function.session-set-save-handler

From: Date: Wed, 02 Nov 2005 16:01:42 +0000
Subject: note 58390 added to function.session-set-save-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-97992@lists.php.net to get a copy of this message
I have something to add to the note from rudy dot metzger at pareto dot nl. As objects are being destroyed before sessions are written as of PHP 5.0.5, we can use a __destruct() method to call session_write_close() in a class-based session handler. It is possible for your session handling class to use other objects. It's just a matter of calling session_write_close() at the end of your script, rather in a __destruct() method. eg. <?php echo "You've been to this page " . $oSession->hits . " times before"; $oSession->hits++; session_write_close(); ?> It's generally best to make declare a function in your common include file(s) that is called at the end of every script on your site. That way you can do any cleanups you need, and also call session_write_close(). ---- Manual Page -- http://www.php.net/manual/en/function.session-set-save-handler.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58390 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58390&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58390&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58390&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58390&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58390&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58390&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58390&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58390&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97992) next »