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

From: Date: Sun, 01 Jan 2023 12:41:37 +0000
Subject: note 128073 added to function.session-set-save-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-220029@lists.php.net to get a copy of this message
Although, session_set_save_handler() has support for saving session data via other modes, This does not support a way for saving session data in COOKIES. This is required for a site with a huge concurrent request the recommended solution by session_set_save_handler() does not fit the load site is handling. So, the other way around to do this is as below. <?php // start.php ob_start(); // Turn on output buffering $sessCookieName = session_name(); $_SESSION = json_decode(base64_decode($_COOKIE[$sessCookieName]), true); // Code function echosess() { echo $_SESSION['id']; } echosess(); $_SESSION['id'] = 1; // end.php $op = ob_get_clean(); // Get current buffer contents and delete current output buffer $encryptedData = base64_encode(json_encode($_SESSION)); setcookie($sessCookieName, $encryptedData, time() + (ini_get("session.gc_maxlifetime")), '/'); echo $op; ?> If more security is required about the data of the session in cookie, then key based encryption/decryption can solve the issue. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.158.213 (proxied: 203.192.243.166) ---- Manual Page -- https://php.net/manual/en/function.session-set-save-handler.php Edit -- https://main.php.net/note/edit/128073 Del: integrated -- https://main.php.net/note/delete/128073/integrated Del: useless -- https://main.php.net/note/delete/128073/useless Del: bad code -- https://main.php.net/note/delete/128073/bad+code Del: spam -- https://main.php.net/note/delete/128073/spam Del: non-english -- https://main.php.net/note/delete/128073/non-english Del: in docs -- https://main.php.net/note/delete/128073/in+docs Del: other reasons-- https://main.php.net/note/delete/128073 Reject -- https://main.php.net/note/reject/128073 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220029) next »