Re: session vars set in functions invalid??

From: Date: Wed, 20 Dec 2000 02:33:32 +0000
Subject: Re: session vars set in functions invalid??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31127@lists.php.net to get a copy of this message
Session variables were added on recently. There really is no concept of a "global" variable on a script-wide basis. It's pretty much a religious issue among Computer Scientists to have it that way (or not). For large-scale projects, it's rather critical, actually, that a variable's scope be limited so that the damage that can be done by variable names clashing is kept to a minimum. Making session variables be global on a script-wide basis would have been very, very tricky, if not downright impossible given the overall design philosophy of PHP. It probably feels odd or even "wrong" if you're coming from ASP or ColdFusion or any other language with a bunch of globals running around. But you'll probably get used to it. ----- Original Message ----- From: Michael Geary <michael.geary@seranova.com> To: <php-general@lists.php.net>; 'Richard Lynch' <richard@zend.com> Sent: Tuesday, December 19, 2000 7:24 PM Subject: RE: [PHP] session vars set in functions invalid?? > Thanks Richard & Hardy for the insights. I now have my scheme working via > the global function. > > However, it still seems very strange to me that session variables would be > affected by scope. Can anyone comment on the intent/value of this? > > -michael > > > ---------- > > From: Richard Lynch > > Sent: Tuesday, December 19, 2000 4:35 PM > > To: php-general@lists.php.net > > Subject: Re: [PHP] session vars set in functions invalid?? > > > > function session_login($username, $password){ > > global $session_id; > > . > > . > > . > > } > > > > Or, have the function *return* the session_id. > > > > Or, provide a pair of functions to read/write the ID, which really just > > alters a global variable. > > > > Or... > > > > ----- Original Message ----- > > From: Michael Geary <michael.geary@seranova.com> > > Newsgroups: php.general > > Sent: Tuesday, December 19, 2000 4:45 PM > > Subject: [PHP] session vars set in functions invalid?? > > > > > > > Hi all, > > > > > > I am trying, as I'm sure many others are, to come up with a compact user > > > authentication/login scheme. > > > > > > It seems to me that for my purposes, the best way to go is to run a > > function > > > which receives the username and supplied password. A lookup in my > > database > > > is performed, and a session variable is set which tells me who the user > > is. > > > > > > My database lookup works just fine. However, It appears that session > > > variable scope doesn't penetrate outside of functions. Can this be? I > > > thought the whole point of session variables was that they are > > accessible > > > from anywhere. If I can't set a session variable within a function, then > > it > > > appears that I have to in-line code the authentication process wherever > > it > > > is needed, which seems rather silly to me. > > > > > > Unless I can get some clarity on this, it seems I will have to roll my > > own > > > session handling using a temporary database table. Can anyone give me > > some > > > help to spare me from this work? > > > > > > Thanks in advance, > > > > > > michael geary > > > > > > -- > > > 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 > > > > > > > > > -- > > 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 (#31127) next »