note 9925 modified in function.session-register by irc-html

From: Date: Fri, 24 May 2002 01:52:50 +0000
Subject: note 9925 modified in function.session-register by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-30965@lists.php.net to get a copy of this message
Note that when you first call session_register('var'), the global $var may already contain a value passed in by GET or POST. It is only after you have called session_register('var') that $var references $HTTP_SESSION_VARS['var'] instead (depending of course on your php.ini configuration). So, my advice is to check or clear the value of $var, the first time you call session_register('var') unless you want a user to try 'http://mydomain/index.php?loggedin=true' on your script that contains code like: <?php session_register('loggedin'); if ($loggedin) { //show secure content } else { //show login } ?> I use the following function to set and register session variables with initial values. function session_var_init($var, $val) { if (!session_is_registered($var)) { session_register($var); $GLOBALS[$var] = $val; } } Note that this function calls session_register() and sets $var to an initial value only if $var is not already registered in the session, thus avoiding the potential GET and POST problem described above. <?php session_var_init('loggedin',false); if ($loggedin) { //show secure content } else { //show login } ?> --was-- Note that when you first call session_register('var'), the global $var may already contain a value passed in by GET or POST. It is only after you have called session_register('var') that $var references $HTTP_SESSION_VARS['var'] instead (depending of course on your php.ini configuration). So, my advice is to check or clear the value of $var, the first time you call session_register('var') unless you want a user to try 'http://mydomain/index.php?loggedin=true' on your script that contains code like: <?php session_register('loggedin'); if ($loggedin) { //show secure content } else { //show login } ?> I use the following function to set and register session variables with initial values. function session_var_init($var, $val) { if (!session_is_registered($var)) { session_register($var); $GLOBALS[$var] = $val; } } Note that this function calls session_register() and sets $var to an initial value only if $var is not already registered in the session, thus avoiding the potential GET and POST problem described above. <?php session_var_init('loggedin',false); if ($loggedin) { //show secure content } else { //show login } ?> http://www.php.net/manual/en/function.session-register.php

« previous php.notes (#30965) next »