note 90115 added to session.examples

From: Date: Tue, 07 Apr 2009 11:24:56 +0000
Subject: note 90115 added to session.examples
Groups: php.notes 
Request: Send a blank email to php-notes+get-152884@lists.php.net to get a copy of this message
I have wrote this following piece of code that shows how to work with global sessions (global to all clients) and private sessions (private per browser instance i.e. session coockie). This code is usefull to store some read-only complex configuration and store it once (per server) and save the performance penatly for doing the same thing over each new private session... Enjoy: <?php // Get the private context session_name('Private'); session_start(); $private_id = session_id(); $b = $_SESSION['pr_key']; session_write_close(); // Get the global context session_name('Global'); session_id('TEST'); session_start(); $a = $_SESSION['key']; session_write_close(); // Work & modify the global & private context (be ware of changing the global context!) ?> <html> <body> <h1>Test 2: Global Count is: <?=++$a?></h1> <h1>Test 2: Your Count is: <?=++$b?></h1> <h1>Private ID is <?=$private_id?></h1> <h1>Gloabl ID is <?=session_id()?></h1> <pre> <?php print_r($_SESSION); ?> </pre> </body> </html> <?php // Store it back session_name('Private'); session_id('$private_id'); session_start(); $_SESSION['pr_key'] = $b; session_write_close(); session_name('Global'); session_id('TEST'); session_start(); $_SESSION['key']=$a; session_write_close(); ?> ---- Server IP: 82.80.248.162 Probable Submitter: 81.218.0.198 ---- Manual Page -- http://www.php.net/manual/en/session.examples.php Edit -- https://master.php.net/note/edit/90115 Del: integrated -- https://master.php.net/note/delete/90115/integrated Del: useless -- https://master.php.net/note/delete/90115/useless Del: bad code -- https://master.php.net/note/delete/90115/bad+code Del: spam -- https://master.php.net/note/delete/90115/spam Del: non-english -- https://master.php.net/note/delete/90115/non-english Del: in docs -- https://master.php.net/note/delete/90115/in+docs Del: other reasons-- https://master.php.net/note/delete/90115 Reject -- https://master.php.net/note/reject/90115 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152884) next »