Re: Sessions and multiple windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Now, the question is, what will PHP do when it starts with page_9? Will
> it unserialize $_SESSION['policeman'] again, even though it already has
> an unserialized instance of $_SESSION['policeman']? If it does
> unserialize, does that mean that it creates a second instance of
> $_SESSION['policeman'], thereby breaking the common link that I am
> trying to provide?

page_9 does not have an unserialized instance of anything.

It is completely independent of page_2.

The $_SESSION variable is being shared, however, in some sense.

Probably the best solution here is to *NOT* store the unserialized
'policeman' in $_SESSION.

Set up a second array for your unserialized stuff, and write a function to
get/set it.

function get_session_data($field){
  global $_UNSERIALIZED;

  if (!isset($_UNSERIALIZED[$field])){
    $_UNSERIALIZED[$field] = unserialize($_SESSION[$field]);
  }
  return $_UNSERIALIZED[$field];
}

function set_session_data($field, $value){
  global $_UNSERIALIZED;

  $_UNSERIALIZED[$field] = $value;
  //$_SESSION[$field] = serialize($value);
}

You can either write a function you call at the end of every script to
serialize everything and put it into $_SESSION, or you can un-comment the
line above.  Depends how much you shuffle in and out of serialized data.

Bottom line:  Don't confuse $_SESSION values by sometimes having
serialized data, and sometimes not in it.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux