Re: Still trying to understand sessions?
| From: | C.R. | Date: | Thu, 24 Apr 2003 01:24:38 +0000 |
| Subject: | Re: Still trying to understand sessions? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145104@lists.php.net to get a copy of this message | ||
Still confused. In my example below, formsave is an array which can contain
multiple variables and can be access like $formsave['name'] for example, but
from my understanding - $_SESSION['name'] only contains one variable - name.
So in order to do the same thing as session_register using $_SESSION, would
I have to use multiple instances? i.e.$_SESSION['name'] = "$POST['name'],
$_SESSION['email'] = "$POST['email'], etc. I just don't understand the
use
of each of these. From what I see session_register seems to be the better
option.
Any thing else you can add to un-confuse me is appreciated.
if (!session_is_registered("formsave")) { // Form Array
session_register("formsave");
}
TIA
----- Original Message -----
From: "Greg Beaver" <greg@chiaraquartet.net>
To: "Matthew Walden" <mwalden@ukonline.co.uk>
Cc: <php-general@lists.php.net>; "C.R." <odcs@rogers.com>
Sent: Wednesday, April 23, 2003 8:38 PM
Subject: Re: Still trying to understand sessions?
> Hi,
>
> For PHP version 4.2.3+, use $_POST instead of $HTTP_POST_VARS,
> $HTTP_POST_VARS is deprecated.
>
> register_session_variable() is only intended to extract $_SESSION array
> contents into global variables.
>
> so,
>
> $_SESSION['myvar'] = 'hello';
>
> is the same as:
>
> register_session_variable('myvar');
> $myvar = 'hello';
>
> or even:
>
> extract($_SESSION);
> $myvar = hello;
>
> Greg
> --
> phpDocumentor
> http://www.phpdoc.org
>
> Matthew Walden wrote:
> > OK I'm no expert, but I've used sessions a few times so I'll try and
> > share what I (think I) know.
> >
> > Firstly, you set session variables like this :
> >
> > session_start();
> > _SESSION['variable_one'] = $variable_one;
> > _SESSION['variable_two'] = $variable_two;
> > etc.
> >
> > Then, you can refer to these variables in any page which calls the
> > session_start() function. So you could say :
> >
> > echo "_SESSION['variable_one']";
> >
> > The formsave isnt an array, its an element index of the _SESSION array
> > defined by PHP.
> >
> > From memory, $HTTP_POST_VARS is the array of variables which have been
> > passed into the document in the address bar, so if you enter :
> >
> > www.website.com/page.php?variable=value
> >
> > Then you can access the variable by saying in your script :
> >
> > $HTTP_POST_VARS['variable']
> >
> > You could also just say $variable, but its safer to expicitly tell it
> > where you want to get it from.
> >
> > Without checking the docs, I'm not sure what the difference is between
> > session_register() and writing it directly into the array like I did
above.
> >
> > I hope thats some help, and maybe someone with better PHP knowledge will
> > correct anything I got wrong :) I got my user authentication working
> > this way, but thats not to say its the right way.
> >
> > C.R. wrote:
> >
> >> I am a little confused about $_SESSION['whatever'],
> >> session_register("whatever");, or $HTTP_SESSION_VARS["whatever"].
> >>
> >> Right now I have a script that uses the following:
> >>
> >> if (!session_is_registered("formsave")) { // Form Array
> >> session_register("formsave");
> >> }
> >>
> >> foreach($HTTP_POST_VARS as $varname => $value)
> >> $formsave[$varname] = trim($value);
> >>
> >> I understand that this is assigning all the variables from my form to
an
> >> array called $formsave. I can then use it something like - echo
> >> $formsave["username']; or whatever else I may need it for - but how do
> >> I do
> >> the same thing with $_SESSION.
> >>
> >> I have downloaded a couple of other scripts that use $_SESSION, but I
> >> want
> >> to convert one or the other so that my scripts are standardized.
> >>
> >> Any help in explaining these differences is appreciated.
> >>
> >> TIA
> >>
> >>
> >>
> >
>
>
>