note 23955 added to ref.session

From: Date: Fri, 02 Aug 2002 05:02:12 +0000
Subject: note 23955 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-34122@lists.php.net to get a copy of this message
Some of the examples listed in the text of this page are a bit misleading. The code as it is will not behave as expected. ## THIS WON'T WORK <?php if (!session_is_registered('count')) { session_register("count"); $count = 0; } else { $count++; } print $count; ?> The code should instead read as follows: ## this code WILL work <?php session_start(); if (!session_is_registered('count')) { session_register("count"); $count = 0; } else { $count++; } print $count; ?> Remember that if you don't call session_start(), you never resume the session that you had started before. In such a case, no session variables are registered, and the session_is_registered() call will always return false, no matter what you pass to it. It's easy to forget the importance of the session_start() function when you're used to using session_register() because: "If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made." (quoted from the session_register() documentation on this site). session_is_registered(), on the other hand, does not make any implicit calls to session_start(). You have to do it yourself. -- http://www.php.net/manual/en/ref.session.php http://master.php.net/manage/user-notes.php?action=edit+23955 http://master.php.net/manage/user-notes.php?action=delete+23955 http://master.php.net/manage/user-notes.php?action=reject+23955

« previous php.notes (#34122) next »