Sessions: suggestions and comments

From: Date: Fri, 23 Mar 2001 22:15:19 +0000
Subject: Sessions: suggestions and comments
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-45353@lists.php.net to get a copy of this message
what i did was implement my own session class so that i can have a single session variable ($s) and have it handle all my session needs via an OO interface ($s->CleanUp(), $s->Update(), ...) consequently, all of my session data is in a simple assoc. array that's a variable of the session class (sdata) so i can get to all of my session data via $s->sdata[...] i update a value by: $s->Update('name', 'newvalue) and start the session: $s = new Session( $cookie_sid ); no mucking around with multiple global variables and such... no registering of variables and worrying about PHP's internals - just one object (and thus, one variable) is all i need for session handling. i dont understand why more people dont use assoc. arrays for their session needs... ive never used PHP's built-in session handling so im not too sure of it's limitations, but are there any (good) reasons why more people dont use associative arrays as their session variables? for example: instead of having a mess of globals: $username $firstname $session_id $this $that you could just register one variable and use it as an assoc. array to store all of the values you needed. ($svar, for instance) $svar['username'] $svar['firstname'] $svar['session_id'] $svar['this'] $svar['that'] this would enable you to take an arbitrary number of variables and cut it down to *one* single assoc array.... seems to be a rather large benefit in doing things this way... so i cannot figure out why i dont see more people taking this road.... -- i come from a perl background, so im used to using hashes (assoc. arrays) for lots of things. i get the feeling that not very many people on this list (newbies, at least) are familiar or comfortable with assoc. arrays. any comments are welcome :) > -----Original Message----- > From: Michael Champagne [mailto:mchampagne@capis.com] > Sent: Friday, March 23, 2001 4:48 PM > To: hi > Cc: php-general@lists.php.net > Subject: Re: [PHP] I don't understand HTTP_SESSION_VARS > > > Maybe I should just go back to using globals then. What does everyone else do > normally? Globals or use the track_vars? I can't get these things working at > all. > > Mike > > > Hi, > > > > That code causes php to crash. I have never had that happen before. Every > > time I try to run that script, I am given an internal server warning. > > > > ""Johnson, Kirk"" <kjohnson@zootweb.com> wrote in message > > > > news:01A4B59FD1EBD311838100A0C98BE0D9AD582E@chef.zootweb.com... > > > Try as below. Note both the global and the session_register statements. > > > > > > > function set session() > > > > { > > > > global $my_session_var,$HTTP_SESSION_VARS; > > > > session_start(); > > > > $my_session_var = "Blah blah"; > > > > session_register($HTTP_SESSION_VARS['my_session_var']); > > > > } > > > > > > Kirk > > > > > > > > > > -----Original Message----- > > > > From: Michael Champagne [mailto:mchampagne@capis.com] > > > > Sent: Friday, March 23, 2001 1:32 PM > > > > To: PHP General Mailing List > > > > Subject: [PHP] I don't understand HTTP_SESSION_VARS > > > > > > > > > > > > I'm still having problems with this. I was able to get > > > > sessions and session > > > > variables working ok with register_globals=on, but I had read > > > > that it was > > > > better not to keep register_globals on so I turned it off and > > > > I'm trying to > > > > figure out how this works now. > > > > > > > > I'm registering a variable in one function say like this: > > > > function set session() > > > > { > > > > global $my_session_var; > > > > session_start(); > > > > $my_session_var = "Blah blah"; > > > > session_register('my_session_var'); > > > > } > > > > > > > > Then I'm trying to read it in another function like this: > > > > function read_session() > > > > { > > > > global $HTTP_SESSION_VARS; > > > > session_start(); > > > > echo ($HTTP_SESSION_VARS[my_session_var]); > > > > } > > > > > > > Michael Champagne, Software Engineer > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > > > > > > > -- > Michael Champagne, Software Engineer > Capital Institutional Services, Inc. > wk: mchampagne@capis.com > hm: mchamp@texas.net > > > > ****************************************************************** > This communication is for informational purposes only. It is not > intended as an offer or solicitation for the purchase or sale of > any financial instrument or as an official confirmation of any > transaction, unless specifically agreed otherwise. All market > prices, data and other information are not warranted as to > completeness or accuracy and are subject to change without > notice. Any comments or statements made herein do not > necessarily reflect the views or opinions of Capital Institutional > Services, Inc. Capital Institutional Services, Inc. accepts no > liability for any errors or omissions arising as a result of > transmission. Use of this communication by other than intended > recipients is prohibited. > ****************************************************************** > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#45353) next »