Re: Problems with Sessions!!!
| From: | Dean Hall | Date: | Wed, 01 Nov 2000 11:08:31 +0000 |
| Subject: | Re: Problems with Sessions!!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23142@lists.php.net to get a copy of this message | ||
> Are session variable passed only when u submit a form
> or can they be picked randomly from files using
> sessions.
Since you mentioned .php3 files, I'm not sure if you're talking about PHP4
session-handling or phplib, but I think they're rather similar, even though
PHP4's is functional and phplib's is OO.
I'll cover PHP4 sessions, as phplib's functionality can easily be
duplicated.
All you have to do is 'session_register("var_name");' and have the variable
'$var_name' set to the value you want, and that session variable is now
available (if you have (I think it's) --enable-track-vars configured. It
should be automatically propogated to the next page you go to on the same
host.
A few things can happen, though:
First, it's only automatically propogated if you're using cookies. If you
want to propogate it through GET (e.g., if the user has cookies disables),
you want to append the constant 'SID' to all your relative URL links. That
will put the session ID in the query string and automatically propogate it
to the next page. If cookies are enabled, 'SID' will be empty, so you don't
need a conditional to append it.
Second, if you're doing a POST form, and cookies aren't enabled, you'll have
to propogate your variables manually by making them "hidden" form fields or
some such thing, reading them in to your form-processor and resetting the
session variables.
But if cookies are enabled, none of this is necessary. The variable should
be automatically available to your present script as well as any pages (even
5-at-a-time) the user goes to next.
> For example, when i'm trying to use a session variable
> that has been registered in one php3 file .. it is not
> read unless i actually submit a form on the first file
> to this new php3 file.
>
> What if i want to pass these session variable values
> to 2 or maybe more files at the same time?
Dean.