note 23955 deleted from ref.session by sniper
| From: | sniper@php.net | Date: | Tue, 21 Jan 2003 03:15:33 +0000 |
| Subject: | note 23955 deleted from ref.session by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-42477@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.