Re: Learning PHP Sessions
| From: | Russ Michell | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: Learning PHP Sessions | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14039@lists.php.net to get a copy of this message | ||
Maybe if you showed us a [small] snippet of the offending code and a procedure of the order of
events, we may be able to help out further.
Regards:
Russ
On Mon, 5 Nov 2001 01:00:23 -0500 Matthew Tedder <matthew@simpflex.com> wrote:
>
> Context: I am using PHP4 from the packages included with Linux Mandrake 8.1
>
> When I register and populate the variable--the variable is shows up empty in
> all the rest of my script. It doesn't seem to matter if it's assigned before
> or after the registration.
>
> Furthermore, neither my book nor the on-line PHP documentation definitively
> explains what session_start() does or session_register() does.
>
> My impression is that session_start() initiates a session if the $PHPSESSID
> is not already read in from the calling page (cooky or CGI variable). If
> $PHPSESSID already exists (from cooky or CGI variable) then it loads any
> associated variables from the previous page....and maintains the same session
> ID as was automatically assigned from the first session_start() without one.
>
> Then session_register() simply marks what variables are to be stored and
> associated with the current session ID. At the end of the script, it stores
> their values for retrieval during the next execution of session_start() where
> the identical session ID is given (via cooky or CGI variables).
>
> But, although I get no errors, my scripts are not holding the values of any
> registered variables even on the same page.... It simply doens't appear to
> have any effect, regardless of what I do.
>
> --Matthew
>
>
> On Wednesday 31 October 2001 11:44 am, you wrote:
> > * session_register('myvar'); creates a session var called $myvar
> > * session_start(); needs to be called from the top of each script that will
> > need the session var $myvar
> > * session_destroy('myvar'); rids you of $myvar completely.
> > * session_destroy('HTTP_SESSION_VARS'); rids you off *all* currently
> > registered session vars
> >
> > Note that a variable used in this way is refered to as 'myvar' and
> > referenced a snormal within the script as: $myvar
> >
> > HTH you out.
> > Russ
> >
> > On Wed, 31 Oct 2001 09:55:33 -0600 Steve Cayford
> <steve_cayford@unioncab.com> wrote:
> > > This is really off-topic for this list, but...
> > >
> > > From my understanding of sessions, you really don't want session_start()
> > > in an if{} block. Every time you hit this script, it will have no memory
> > > of any session variables until you call session_start().
> > >
> > > -Steve
> > >
> > > On Tuesday, October 30, 2001, at 02:30 PM, Matthew Tedder wrote:
> > > > <?php
> > > > /*
> > > > Hi,
> > > >
> > > > I'm new to PHP and am having trouble understanding how to use PHP
> > > > sessions. My book tells in near the beginning how to start them and
> > > > register
> > > > session variables, but I can't figure out how to destroy a session or
> > > > later
> > > > read those session variables. I'm also trying to do this across
> > > > frames, but
> > > > can't even get it to work within a single page.
> > > >
> > > > Here's what I've learned so far and what my problems are:
> > > > */
> > > >
> > > > /* To start a session */
> > > > session_start();
> > > >
> > > > /* To register a session variable */
> > > > session_register("myvar");
> > > > $myvar = "some value";
> > > >
> > > > /*
> > > > PROBLEM #1: From the above commands, I get a $PHPSESSID that seems to
> > > > be
> > > > globally available for use, but I cannot seem to read my values back
> > > > out of
> > > > the registered session variable from anywhere... I tried:
> > > > */
> > > >
> > > > print "$myvar\n"; /* and absolutely nothing is printed */
> > > >
> > > > /* To destroy a session */
> > > > session_destroy();
> > > >
> > > > /*
> > > > PROBLEM #2: This says there is no session to destroy. It's rather
> > > > strange
> > > > because I can still print the $PHPSESSID value..
> > > >
> > > > I've attached my code...
> > > >
> > > > */
> > > > ?>
> > > > --
> > > > PHP Database Mailing List (http://www.php.net/)
> > > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> > > > For additional commands, e-mail: php-db-help@lists.php.net
> > > > To contact the list administrators, e-mail:
> > > > php-list-admin@lists.php.net
> > >
> > > --
> > > PHP Database Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> > > For additional commands, e-mail: php-db-help@lists.php.net
> > > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
> > #-------------------------------------------------------#
> >
> > "Believe nothing - consider everything"
> >
> > Russ Michell
> > Anglia Polytechnic University Webteam
> > Room 1C 'The Eastings' East Road, Cambridge
> >
> > e: r.j.michell@apu.ac.uk
> > w: www.apu.ac.uk/webteam
> >
> > www.theruss.com
> >
> > #-------------------------------------------------------#
#-------------------------------------------------------#
"Believe nothing - consider everything"
Russ Michell
Anglia Polytechnic University Webteam
Room 1C 'The Eastings' East Road, Cambridge
e: r.j.michell@apu.ac.uk
w: www.apu.ac.uk/webteam
www.theruss.com
#-------------------------------------------------------#