Re: [PHP-DB] Learning PHP Sessions
one problem I see, you are trying to populate the variable after you register it. session_start(); $myvar = "something"; session_register('myvar'); echo $myvar; Jim Lucas - Original Message - From: "Russ Michell" <[EMAIL PROTECTED]> To: "Steve Cayford" <[EMAIL PROTECTED]> Cc: "Matthew Tedder" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, October 31, 2001 8:44 AM Subject: Re: [PHP-DB] Learning PHP Sessions > > * session_register('myvar'); creates a session var called $myvar > * session_start(); needs to be called from the top of each script that will need the session var > $myvar > * session_destroy('myvar'); rids you of $myvar completely. > * session_destroy('HTTP_SESSION_VARS'); rids you off *all* currently registered session vars > > Note that a variable used in this way is refered to as 'myvar' and referenced a snormal within the > script as: $myvar > > HTH you out. > Russ > > On Wed, 31 Oct 2001 09:55:33 -0600 Steve Cayford <[EMAIL PROTECTED]> wrote: > > > This is really off-topic for this list, but... > > > > From my understanding of sessions, you really don't want session_start() > > in an if{} block. Every time you hit this script, it will have no memory > > of any session variables until you call session_start(). > > > > -Steve > > > > On Tuesday, October 30, 2001, at 02:30 PM, Matthew Tedder wrote: > > > > > > > /* > > > 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: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > #---# > > "Believe nothing - consider everything" > > Russ Michell > Anglia Polytechnic University Webteam > Room 1C 'The Eastings' East Road, Cambridge > > e: [EMAIL PROTECTED] > w: www.apu.ac.uk/webteam > > www.theruss.com > > #---# > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Learning PHP Sessions
* session_register('myvar'); creates a session var called $myvar * session_start(); needs to be called from the top of each script that will need the session var $myvar * session_destroy('myvar'); rids you of $myvar completely. * session_destroy('HTTP_SESSION_VARS'); rids you off *all* currently registered session vars Note that a variable used in this way is refered to as 'myvar' and referenced a snormal within the script as: $myvar HTH you out. Russ On Wed, 31 Oct 2001 09:55:33 -0600 Steve Cayford <[EMAIL PROTECTED]> wrote: > This is really off-topic for this list, but... > > From my understanding of sessions, you really don't want session_start() > in an if{} block. Every time you hit this script, it will have no memory > of any session variables until you call session_start(). > > -Steve > > On Tuesday, October 30, 2001, at 02:30 PM, Matthew Tedder wrote: > > > > /* > > 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: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > #---# "Believe nothing - consider everything" Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Learning PHP Sessions
This is really off-topic for this list, but... From my understanding of sessions, you really don't want session_start() in an if{} block. Every time you hit this script, it will have no memory of any session variables until you call session_start(). -Steve On Tuesday, October 30, 2001, at 02:30 PM, Matthew Tedder wrote: > /* > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Learning PHP Sessions
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" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, October 30, 2001 12:30 PM Subject: [PHP-DB] Learning PHP Sessions > /* > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Learning PHP Sessions
>=*/ if(!isset($PHPSESSID)) { session_start(); session_register("UserName"); session_register("UserPage"); $UserName = "guest"; $UserPage = "Home"; }; /*=<< Main Switchboard for Pages >>=*/ include "includes/bodyhead.html"; switch($action) { case "Home": ShowHome(); break; case "Login": ShowLogin(); break; case "AuthUser": AuthUser($UserName, $UserPassword); break; case "Logout": ShowLogout(); break; default: ShowMessage("Service Not Yet Implemented"); break; } include "includes/bodyfoot.html"; /*=<< Function To Show Home Page >>=*/ function ShowHome() { include "includes/home.html"; } /*=<< Function To Show Login Page >>=*/ function ShowLogin() { print "\n"; print "\n"; print "\n"; print "USER AUTHORIZATION\n"; print "\n"; print "\n"; print "\n"; print "User Name:\n"; print "\n"; print "\n"; print "\n"; print "Password:\n"; print "\n"; print "\n"; print "\n"; print " \n"; print "\n"; print "\n"; print "\n"; print "\n"; print "UNAUTHORIZED ENTRY IS PUNISHABLE BY LAW\n"; print "\n"; print "\n"; } /*=<< Function Authenticate User (from Login Page) >>=*/ function AuthUser($User, $User) { if($User == "guest") { ShowMessage("For guest users, authorization is not required. However, priviledges are limited."); } else { ShowMessage("Authorization Feature Not Yet Implemented"); } } /*=<< Function To Logout User >>=*/ function ShowLogout() { ShowMessage("Your Session Has Been Terminated.\nThank You for Properly Logging Out, $UserName!"); session_destroy(); } /*=<< Function To Show Generic Messages >>=*/ function ShowMessage($message) { print "\n"; print "\n"; print "$message\n"; print "\n"; } ?> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]