Re: Problem with session vars !
| From: | Yasuo Ohgaki | Date: | Mon, 23 Apr 2001 15:30:31 +0000 |
| Subject: | Re: Problem with session vars ! | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-8820@lists.php.net to get a copy of this message | ||
It not related to database. Anyway,
If you use $HTTP_SESSION_VARS, forget about session_(un)register(). (Do not use
them)
Just use $HTTP_SESSION_VARS. It's known issue.
(If you use global vars, only use global vars and use session_(un)register())
Regards,
--
Yasuo Ohgaki
""Nicolas Guilhot"" <nguilhot@gphy.campus.univ-poitiers.fr> wrote in
message
news:NEBBLNMCKLOGFKNONHDAAEBKCBAA.nguilhot@gphy.campus.univ-poitiers.fr...
> I am having problem with PHP4 session variables. I think I misunderstood how
> they work, and I can't see what I'm doing wrong. Any help would be
> appreciated. I am using the version from EasyPhp 1.1.1.
>
> Below is a short example to explain my problem. I've got two php scripts.
> 'test1.php' which start a session, set a variable $sess and register it as a
> session variable. It then redirects to 'test2.php' which only displays
> session variables and switches $sess[var1] between true and false on each
> call.
>
> With the code in example, I retrieve the variable set by 'test1.php' on
> 'test2.php', but $HTTP_SESSION_VARS['sess']['var1'] is always
> true.
> With the same code, If I set register_globals to off in my php.ini, I get
> the opposite. I never retrieve the variable set by 'test1.php' on
> 'test2.php', but $HTTP_SESSION_VARS['sess']['var1'] is switches
> correctly.
>
> What is wrong in this code ??
>
> If I replace
> session_register('sess'); in 'test1.php'
> by
> $GLOBALS['HTTP_SESSION_VARS']['sess'] = $sess;
> and set register_globals to off everything works. Someone could explain to
> me why ??
>
> Best regards,
>
> Nicolas
>
>
>
> File test1.php
> <?
> function initSessionVar()
> {
> global $sess;
> // initialise sess variable for the new session
> $sess = array();
> $sess['user'] = "test";
> $sess['var1'] = true;
>
> session_register('sess');
> }
> session_start();
> initSessionVar();
>
> header('Location: http://localhost/test2.php');
> exit;
> ?>
>
> File test2.php
> <?
> session_start();
>
> echo gettype($HTTP_SESSION_VARS['sess']) . "<BR>";
> echo $HTTP_SESSION_VARS['sess']['user'] . "<BR>";
> echo ($HTTP_SESSION_VARS['sess']['var1'] ? "true" :
> "false");
>
> if ($HTTP_SESSION_VARS['sess']['var1']){
> $HTTP_SESSION_VARS['sess']['var1'] = false;
> }
> else{
> $HTTP_SESSION_VARS['sess']['var1'] = true;
> }
> ?>
>
>
> --
> 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
>