Re: understanding session vars ?
| From: | Gregory Machin | Date: | Thu, 24 Nov 2005 10:34:54 +0000 |
| Subject: | Re: understanding session vars ? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-226405@lists.php.net to get a copy of this message | ||
My test code is for test.php which is intended to call it's self, and starts
with sesstion_start().
buy does not disply x after link2 is clicked on, but only y..
what am I missing ?
Thanks
On 11/24/05, David Grant <david@grant.org.uk> wrote:
>
> Gregory,
>
> Values in the $_SESSION superglobal will persist over pages so long as
> session_start() is called on each page.
>
> Cheers,
>
> David Grant
>
> Gregory Machin wrote:
> > I have a test script..
> > What i'm trying to achieve is once the user has clicked on link1 the
> > value of item must equal x and if the user clicks on link2 the value of
> > items must stay equal to x while setting action equal to y ..
> >
> > <?php
> > session_start();
> > echo 'Welcome to testpg';
> > $_SESSION['time'] = time();
> >
> >
> > if (isset($_GET['item'])){
> > $_SESSION['item'] = $_GET['item'];
> > echo $_SESSION['item'];
> > }
> >
> > if (isset($_GET['action'])){
> > $_SESSION['action'] = $_GET['action'];
> > echo $_SESSION['action'];
> > }
> >
> >
> > ?>
> > <html><br /><a href="test.php?item=x&<?php echo
> > strip_tags(SID);
> > ?>">link1</a></html>
> > <html><br /><a href="test.php?action=y&<?php echo
> > strip_tags(SID);
> > ?>">link2</a></html>
> >
> > thanks
> >
> > On 11/24/05, * David Grant* <david@grant.org.uk
> > <mailto:david@grant.org.uk>> wrote:
> >
> > Gregory,
> >
> > Are you always setting $_SESSION['menu'] to the contents of
> > $_GET['menu']? If so, the second link will set $_SESSION['menu']
> > to
> > null. You need to check the contents of $_GET['menu'] first before
> > setting, i.e.
> >
> > if (isset($_GET['menu']))
> > $_SESSION['menu'] = $_GET['menu'];
> >
> > Cheers,
> >
> > David Grant
> >
> > Gregory Machin wrote:
> > > Hi
> > > I'm a bit stuck on session var, and thier implamentation, or my
> > perseption
> > > thier of.
> > > I have a page and need certian vars to be persistat each time the
> > page is
> > > called.
> > > This is done to detmin the content of the page through logic that
> > calls
> > > different includes.
> > >
> > > But I cant get the vars to be persistant.
> > > note the page call it's self.
> > >
> > > ./index.php
> > > <?php
> > > session_start();
> > > $_SESSION['menu']
> > >
> > > ?>
> > > <html><A href=./index.php?menu=1>option 1</A></html> //
> > > this works
> > > <html><A href=./index.php?other=do>differnt
> > > action</A></html> //
> > this brakes
> > > it . when the user links here the 'menu' var is cleared
> > > <?php $_SESSION['menu'] = $_GET['menu'];
> > > echo $_SESSION['menu'];
> > >
> > > ?>
> > >
> > > I would like the menu var (and others) to be persistant until it
> > is reset or
> > > updated. how do I acheave this .
> > >
> > > Thanks
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Gregory Machin
> > > greg@linuxpro.co.za
> > > <mailto:greg@linuxpro.co.za>
> > > gregory.machin@gmail.com <Ï
> > > À[s™$§íg³›íEQmailto:gregory.machin@gmail.com>
> > > www.linuxpro.co.za
> > > <http://www.linuxpro.co.za>
> > > www.exponent.co.za
> > > <http://www.exponent.co.za>
> > > Web Hosting Solutions
> > > Scalable Linux Solutions
> > > www.iberry.info <http://www.iberry.info>
> > > (support and admin)
> > >
> > > +27 72 524 8096
> >
> >
> >
> >
> > --
> > Gregory Machin
> > greg@linuxpro.co.za <mailto:greg@linuxpro.co.za>
> > gregory.machin@gmail.com
> > <mailto:gregory.machin@gmail.com>
> > www.linuxpro.co.za <http://www.linuxpro.co.za>
> > www.exponent.co.za <http://www.exponent.co.za>
> > Web Hosting Solutions
> > Scalable Linux Solutions
> > www.iberry.info <http://www.iberry.info> (support
> > and admin)
> >
> > +27 72 524 8096
>
>
--
Gregory Machin
greg@linuxpro.co.za
gregory.machin@gmail.com
www.linuxpro.co.za
www.exponent.co.za
Web Hosting Solutions
Scalable Linux Solutions
www.iberry.info (support and admin)
+27 72 524 8096