|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-03-16 09:29 UTC] mfischer@php.net
Description:
------------
When I use custom session handling functions and use the following session functions in this order:
[...]
session_set_save_handler(...)
[...]
session_start()
[...]
session_destroy()
[...]
session_start()
I get
"Fatal error: session_start(): Failed to initialize storage module: user (path: /var/lib/php4) in test.php on line 9"
After session_destroy is called, the functions assigned with session_set_save_handler() do not work anymore and have to be assigned again.
By calling session_set_save_handler() again after session_destroy() it will work.
This applies to 4.9.10 and 5.0.3 as well.
I think the cause is in session.c in php_session_destroy:
[...]
if (PS(mod)->s_destroy(&PS(mod_data), PS(id) TSRMLS_CC) == FAILURE) {
retval = FAILURE;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session object destruction failed");
}
php_rshutdown_session_globals(TSRMLS_C);
php_rinit_session_globals(TSRMLS_C);
[...]
First, the user defined destroy-handler is called then php_rshutdown_session_globals and then php_rinit_session_globals. In php_rinit_session_globals PS(mod_data) is cleared
static void php_rinit_session_globals(TSRMLS_D)
{
PS(id) = NULL;
PS(session_status) = php_session_none;
PS(mod_data) = NULL;
PS(http_session_vars) = NULL;
}
which is a struct for the user defined functions.
The current documentation says:
"session_destroy() destroys all of the data associated with the current session."
But it seems to do more: it also clears any custom set session save handlers which unexpected.
Reproduce code:
---------------
<?php
function dummy() { }
session_set_save_handler('dummy', 'dummy', 'dummy', 'dummy', 'dummy', 'dummy');
session_start();
session_destroy();
# comment in the next line and the test works
#session_set_save_handler('dummy', 'dummy', 'dummy', 'dummy', 'dummy', 'dummy');
session_start();
?>
Expected result:
----------------
No fatal error message
Actual result:
--------------
Fatal error: session_start(): Failed to initialize storage module: user
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 20:00:01 2025 UTC |
PS(mod_data) gets set to NULL with these: session_write_close(), session_module_name('foo'), session_destroy()I struggled for several days with the "Failed to initialize storage module: user" problem. I read everything I could find on php.net and in this bug database. Finally, what solved the problem for me was this: Whenever I made a call in my code to session_start(), I used an include statement to include the following from an include file: <?php ini_set("session.save_handler", "files"); session_start(); ?> And that did it.I've experienced this problem today, and it was driving me crazy. I was able to resolve it thanks to the last post on this page. I've put this two lines of code ini_set("session.save_handler", "files"); session_start(); in a separate file, and I include them where I need. The strange thing is that I borrowed the piece of code I am using from a GPL portal system, which is working like a charm on my local server with this line ini_set('session.save_handler', 'files'); This is really strange. Anyhow, thank you all guys.