note 27163 deleted from ref.session by sniper

From: Date: Tue, 21 Jan 2003 03:12:45 +0000
Subject: note 27163 deleted from ref.session by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-42468@lists.php.net to get a copy of this message
I had some problems getting the session feature to work, but got there in the end. Key phrases: new session_id, passing session_id, create session_id, renew session_id, PHP Version 4.2.3 The page below should point you in the right direction. Save it as session.php _______________________________________________________________ <HTML> <HEAD> </HEAD> <BODY> <?php session_start(); /* Start the session. This also looks for the PHPSESSID value to be passed in (via GET or POST, I think??) and sets the session_id to that value. */ $ID1 = session_id(); print "IN SESSION --> " . $ID1; /* Check if the 'session' array has been defined. If not set up the array with key names 'state', 'name' and 'password'. Also, initialize another variable called 'counter' and set it 0. */ if (!isset($_SESSION["session"])) { $_SESSION["session"]["state"] = 1; $_SESSION["session"]["name"] = "my_user_name"; $_SESSION["session"]["password"] = "some_password"; $_SESSION["counter"] = 0; /* Print out the 'session' array members by key name and the 'counter' variable. */ print "</BR>'name' set to: " . $_SESSION["session"]["name"] . "\n"; print "</BR>'password' set to: " . $_SESSION["session"]["password"] . "\n"; print "</BR>'state' set to: " . $_SESSION["session"]["state"]; print "</BR>'counter' set to: " . $_SESSION["counter"]; } else { print "</BR>Session is set"; $_SESSION["counter"]++; print "</BR>'counter' session variable set to --> " . $_SESSION["counter"]; } print "</BR>"; // Iterate through the 'session' array print "</BR>About to iterate through array:"; foreach($_SESSION["session"] As $item) { print "</BR>$item"; } /* Create a link back to this page. 'PHPSESSID' is the name of a value that start_session() queries in order to continue the session, if this is not set then the session_start() will create a new session_id. $ID1 was set to the value of session_id() at the top of page. */ print "</BR><a href=\"session.php?&PHPSESSID=$ID1\">Reload page</a>"; ?> </BODY> </HTML> ______________________________________________________________ Mark

« previous php.notes (#42468) next »