sessions help
| From: | Leston Drake | Date: | Thu, 13 Jun 2002 20:46:10 +0000 |
| Subject: | sessions help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102055@lists.php.net to get a copy of this message | ||
Hi again. Thanks to Miguel and Matt for pointing me to sessions for retaining variables.
I've got the register_globals directive set to Off. I want to store a value in a session variable.
I've set up two documents (one that sets a session variable, and one that retrieves it), with the following code.
In doc 1, I've got this code:
function sessionSetNode ($node_id) {
return ($_SESSION['node'] = $node_id);} sessionSetNode("10.2"); Doc 2 looks like this: if (!empty($_SESSION)) {
extract($_SESSION);} else if (!empty($HTTP_SESSION_VARS)) {
extract($HTTP_SESSION_VARS);} function sessionGetNode () {
return $_SESSION['node'];} $n = sessionGetNode(); echo ("Node is $n."); First, I load Doc 1 (to set the session variable). Then I load Doc 2 to retrieve the variable. When doc 2 runs, I get the following: -------------------------------------------------------------------------------------------------------------- Warning: Undefined variable: _SESSION in c:\...\getsessionvar.php on line 17 Node is . -------------------------------------------------------------------------------------------------------------- Line 17 is the } after the line return $_SESSION['node']; It doesn't seem to know about $_SESSION. Can someone help me out? TIA, Leston