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 starts 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 General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to