note 121352 deleted from function.session-register by cmb

From: Date: Wed, 24 Feb 2021 12:11:08 +0000
Subject: note 121352 deleted from function.session-register by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-219182@lists.php.net to get a copy of this message
Note Submitter: pike-php at kw dot nl ---- There are a few compat functions for session_register here that had me tripped up. 1) when registering a session var, the value of the global you are registering should *not* override an existing session value. that would defeat the purpose of the session. instead the global should be refered to the sessions value. 2) the global should become a reference to the sessions value, so that when you change the globals value later, the session variable should change too. This is what I'm using now <?php if (!function_exists('session_register')) { function session_register($name){ global $$name; if (!isset($_SESSION[$name])) { $_SESSION[$name] = $$name; } $$name = &$_SESSION[$name]; } } ?>

« previous php.notes (#219182) next »