Re: Learning PHP Sessions

From: Date: Wed, 31 Oct 2001 02:18:01 +0000
Subject: Re: Learning PHP Sessions
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-13877@lists.php.net to get a copy of this message
You do not need to destroy session variables. You can session_unregister() them, if you'd like. $session_start(); $foo = "Hi"; session_register("foo"); Next page... if (isset($foo)) { echo "$foo"; // will print "Hi" if done correctly session_unregister("foo"); } Sessions are automatically destroyed when the client-side browser shuts down and the garbage collector runs. If you want to "force" a session deletion, use session_destroy(). Use it with caution, though, since it's usually better to let the garbage collector do the work periodically instead of cleaning up each session individually. Check out http://www.php.net/manual/en/ref.session.php 'Luck -Szii ----- Original Message ----- From: "Matthew Tedder" <matthew@tedder.com> To: <php-db@lists.php.net> Sent: Tuesday, October 30, 2001 12:30 PM Subject: [PHP-DB] Learning PHP Sessions > <?php > /* > Hi, > > I'm new to PHP and am having trouble understanding how to use PHP > sessions. My book tells in near the beginning how to start them and register > session variables, but I can't figure out how to destroy a session or later > read those session variables. I'm also trying to do this across frames, but > can't even get it to work within a single page. > > Here's what I've learned so far and what my problems are: > */ > > /* To start a session */ > session_start(); > > /* To register a session variable */ > session_register("myvar"); > $myvar = "some value"; > > /* > PROBLEM #1: From the above commands, I get a $PHPSESSID that seems to be > globally available for use, but I cannot seem to read my values back out of > the registered session variable from anywhere... I tried: > */ > > print "$myvar\n"; /* and absolutely nothing is printed */ > > /* To destroy a session */ > session_destroy(); > > /* > PROBLEM #2: This says there is no session to destroy. It's rather strange > because I can still print the $PHPSESSID value.. > > I've attached my code... > > */ > ?> ---------------------------------------------------------------------------- ---- > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#13877) next »