Re: Still trying to understand sessions?
| From: | Matthew Walden | Date: | Wed, 23 Apr 2003 23:35:50 +0000 |
| Subject: | Re: Still trying to understand sessions? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145098@lists.php.net to get a copy of this message | ||
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 Arraysession_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