Buyocat Posted August 12, 2006 Share Posted August 12, 2006 I wanted to store the session data in an object, so I created a class that looks more or less like this:[code]class Session_Container{ public $_sdata; public function __construct () { session_name('somename'); session_set_cookie_params(3600); session_start(); $this->_sdata = array(); foreach ($_SESSION as $key => $value) { $this->_sdata[$key] = $value; } } public function __destruct() { foreach ($this->_sdata as $key => $value) { $_SESSION[$key] = $value; } }}[/code]I think it is pretty clear what the above code is meant to do; as a side note this code works successfully on my local machine. However on my webserver the session data fails to stick from page to page. I have tried echoing things and checking for sessions in teh destructor and everything seems to be set. To make things more troublesome if I convert the above into a simple script that performs the same function the session data does stick. Lastly, if I move the second loop out of the destructor and into the constructor or any other method then the session data sticks as well. So, it seems like the destructor is the culprit only I'm not exactly sure why. The session appears to be set right before the foreach loop in the method and the sdata array is populated. Does anyone have any ideas on how to get around this issue? Link to comment https://forums.phpfreaks.com/topic/17319-manipulating-the-_session-array-in-the-__destruct-method/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.