note 129814 added to sessionupdatetimestamphandlerinterface.updatetimestamp

From: Date: Wed, 23 Oct 2024 07:56:15 +0000
Subject: note 129814 added to sessionupdatetimestamphandlerinterface.updatetimestamp
Groups: php.notes 
Request: Send a blank email to php-notes+get-221605@lists.php.net to get a copy of this message
Example of using $sessionData available in updateTimestamp function. This is useful when we try to use cookie as a container to save session data. In cookie we need to maintain the access timestamp on similar lines of access time of file. Here we have session.serialize_handler as php_serialize to use serialize() and unserialize() for session encoded data. <?php public function updateTimestamp($sessionId, $sessionData) { $sessionDataArr = unserialize($sessionData); $sessionDataArr['_TS_'] = $this->currentTimestamp; $sessionData = serialize($sessionDataArr); $cookieData = $this->encryptData($sessionData); if (strlen($cookieData) > 4096) { ob_end_clean(); die('Session data length exceeds max 4 kilobytes (KB) supported per Cookie'); } return setcookie( $name = $this->sessionDataName, $value = $cookieData, $options = [ 'expires' => 0, 'path' => '/', 'domain' => '', 'secure' => ((strpos($_SERVER['HTTP_HOST'], 'localhost') === false) ? true : false), 'httponly' => true, 'samesite' => 'Lax' ] ); } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 203.194.97.191) ---- Manual Page -- https://php.net/manual/en/sessionupdatetimestamphandlerinterface.updatetimestamp.php Edit -- https://main.php.net/note/edit/129814 Del: integrated -- https://main.php.net/note/delete/129814/integrated Del: useless -- https://main.php.net/note/delete/129814/useless Del: bad code -- https://main.php.net/note/delete/129814/bad+code Del: spam -- https://main.php.net/note/delete/129814/spam Del: non-english -- https://main.php.net/note/delete/129814/non-english Del: in docs -- https://main.php.net/note/delete/129814/in+docs Del: other reasons-- https://main.php.net/note/delete/129814 Reject -- https://main.php.net/note/reject/129814 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221605) next »