Re: Session Variables ~ Best Practices

From: Date: Tue, 13 Jul 2004 17:03:13 +0000
Subject: Re: Session Variables ~ Best Practices
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-190372@lists.php.net to get a copy of this message
> I presume I am right in assuming that I can declare variables anywhere I > like providing I have started a session on the page but I cannot > actually use those variables until a post or some similar action has > been performed by the user. No, you can use them right away - they are stored server-side, so you don't need to wait for a request/response loop before reading them: session_start(); $_SESSION['foo'] = 'bar'; echo $_SESSION['foo']; // 'foo' is available immediately No need to perform any special declarations. It's cookies that need to wait for a subsequent request to be available via getcookie(). Careful with your session variable naming - you may want to implement a primitive namespace, by using named arrays in $_SESSION, such as $_SESSION['auth']['username'] or $_SESSION['prefs']['boxers_or_briefs']. -mike. --------------------------------------------------------------------- michal migurski- contact info and pgp key: sf/ca http://mike.teczno.com/contact.html

« previous php.general (#190372) next »