Re: Sessions and multiple windows

From: Date: Tue, 07 Dec 2004 19:33:59 +0000
Subject: Re: Sessions and multiple windows
Groups: php.general 
Request: Send a blank email to php-general+get-203689@lists.php.net to get a copy of this message
Richard Lynch wrote:
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. Thanks Richard, Mike and Jason
I think I will need to sit down and sift through all the gen you guys have given me, and decide which solution works best for me. -- Rory McKinley Nebula Solutions +27 21 555 3227 - office +27 21 551 0676 - fax +27 82 857 2391 - mobile www.nebula.co.za ==================== -- Rory McKinley Nebula Solutions +27 21 555 3227 - office +27 21 551 0676 - fax +27 82 857 2391 - mobile www.nebula.co.za ====================

« previous php.general (#203689) next »