tags:

views:

62

answers:

1

I have a non CMS page in which a session value is stored using PHP's default session handler. ie:

session_start();
$_SESSION['MyVar'] = true;

On another page, which is part of the CMS, I need to test whether the variable is true or not. But, the CMS uses it's own session handler, so when I try to read the variable, it's undefined, because it's looking for it in the CMS's session storage system, not PHP's default.

How can I switch over for a moment and read a value from the default session store, and then reinstate the CMS's so that it functions correctly?

Something like:

$SessionHandler = session_get_current_handler(); // save the CMS session handler
session_use_default(); // Use PHP's default handler
$Value = $_SESSION['MyVar']; // Get the value I need
session_set_handler($SessionHandler); // Restore CMS handler
A: 

At some point you will need to call session_start() in order to populate the $_SESSION superglobal array. You 'might' be able to call session_write_close(), change the handler, and do session_start() again.

Try it, it will look something like

$Sessionhandler = session_get_current_handler();
session_use_default();
session_start();
$value = $_SESSION['var'];
session_write_close();
session_set_handler($Sessionhandler);
session_start();

I almost doubt it is going to work though. The only reason it 'might' work is because of the session_write_close() as PHP normally throws an E_NOTICE if you try to call session_start() twice.

Depending upon the implementation, it might try to get the data again. But a lot of people over at the documentation comments have seen weird things happen when calling session_start() twice, even after session_write_close()

Chacha102