note 128181 added to class.sessionhandler

From: Date: Thu, 02 Feb 2023 22:06:10 +0000
Subject: note 128181 added to class.sessionhandler
Groups: php.notes 
Request: Send a blank email to php-notes+get-220137@lists.php.net to get a copy of this message
The best way to set up your own session handler is to extend the native SessionHandler (override the 7 methods + constructor as per your need, keeping the same signatures). Optionally, you can also implement SessionUpdateTimestampHandlerInterface if you plan to use 'lazy_write': Option 1: class MyOwnSessionHandler extends \SessionHandler { ..... } Option 2: class MyOwnSessionHandler extends \SessionHandler implements \SessionUpdateTimestampHandlerInterface { ..... } I would NOT recommend to do this: class MyOwnSessionHandler implements \SessionHandlerInterface, \SessionIdInterface, \SessionUpdateTimestampHandlerInterface { ... } If you are curious, here are the methods called in the order (using PHP 8.2 with XAMPP v3.3.0 on Windows 11 64-bit): - open (always called) - validateId and/or create_sid: validateId is called if you implement SessionUpdateTimestampHandlerInterface. If validation fails, create_sid is called. create_sid is called if a new session ID is needed: new session, etc. - read (always called) - write OR updateTimestamp OR destroy: if you call 'destroy', neither 'write' or 'updateTimestamp' is called, if you have the 'lazy_write' on AND implemented SessionUpdateTimestampHandlerInterface, then 'updateTimestamp' is called instead of 'write' if nothing changes. - close (always called) ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.158.213 (proxied: 24.138.6.76) ---- Manual Page -- https://php.net/manual/en/class.sessionhandler.php Edit -- https://main.php.net/note/edit/128181 Del: integrated -- https://main.php.net/note/delete/128181/integrated Del: useless -- https://main.php.net/note/delete/128181/useless Del: bad code -- https://main.php.net/note/delete/128181/bad+code Del: spam -- https://main.php.net/note/delete/128181/spam Del: non-english -- https://main.php.net/note/delete/128181/non-english Del: in docs -- https://main.php.net/note/delete/128181/in+docs Del: other reasons-- https://main.php.net/note/delete/128181 Reject -- https://main.php.net/note/reject/128181 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220137) next »