You are here: Re: [PHP] understanding session vars ? « PHP « IT news, forums, messages
Re: [PHP] understanding session vars ?

Posted by David Grant on 11/24/05 12:32

Gregory

Gregory Machin wrote:
> 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 ?

"x" wouldn't display because it depends on $_GET['item'] being set,
which isn't. Try var_dump($_SESSION) instead of the conditional echoing
of the variables.

Cheers,

David Grant

> Thanks
>
> On 11/24/05, *David Grant* <david@grant.org.uk
> <mailto: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>
> > <mailto: 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>
> <mailto:greg@linuxpro.co.za <mailto:greg@linuxpro.co.za>>
> > > gregory.machin@gmail.com <mailto:gregory.machin@gmail.com>
> <mailto: gregory.machin@gmail.com <mailto:gregory.machin@gmail.com>>
> > > www.linuxpro.co.za <http://www.linuxpro.co.za>
> <http://www.linuxpro.co.za>
> > > www.exponent.co.za <http://www.exponent.co.za>
> <http://www.exponent.co.za>
> > > Web Hosting Solutions
> > > Scalable Linux Solutions
> > > www.iberry.info <http://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>
> <mailto:greg@linuxpro.co.za <mailto:greg@linuxpro.co.za>>
> > gregory.machin@gmail.com <mailto:gregory.machin@gmail.com>
> <mailto:gregory.machin@gmail.com <mailto:gregory.machin@gmail.com>>
> > www.linuxpro.co.za <http://www.linuxpro.co.za>
> <http://www.linuxpro.co.za >
> > www.exponent.co.za <http://www.exponent.co.za>
> <http://www.exponent.co.za>
> > Web Hosting Solutions
> > Scalable Linux Solutions
> > www.iberry.info <http://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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация