Re: Acessing session vars

From: Date: Fri, 15 Aug 2003 17:36:58 +0000
Subject: Re: Acessing session vars
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-159731@lists.php.net to get a copy of this message
From: "Ed Curtis" <ed@homes2see.com> > I just started using sessions and am having some trouble understanding how > to pull values out of sessions to use in another page. > > I set the values as: > > session_start(); > session_register{'magazine'); > session_register('company'); > > The data is saved as a session because I can read the file located in my > /tmp directory. > > Now I click on a link and go to a different page and I do: > > session_start() > > Magazine: <? echo $magazine; ?> > > Company: <? echo $company; ?> > > Should I be able to retrieve the values in this fashion? I'm using php > 4.1.2. As you sit there and wait for us to answer, you could have taken the 5 second to run this yourself and test it. If register_globals is ON, then yes, that's how you do it. You may want to actually assign a value to $magazine and $company in the first script, though, if you want to see any results. If register_globals is OFF, then you should do it this way: Page 1: session_start(); $_SESSION['magazine'] = 'some value'; $_SESSION['company'] = 'some other value'; Page 2: <?php session_start(); ?> Magazine: <?php echo $_SESSION['magazine']; ?> Company: <?php echo $_SESSION['company']; ?> ---John Holmes...

« previous php.general (#159731) next »