Session class: Storing sessions in a database
Posted: Mon Aug 21, 2006 2:42 pm
Ok, after several days I gave up and decided to post here for help.
I wrote a session class, something along these lines:
Now I have exp.php with this code:
The problem is that I keep getting this error:
Fatal error: session_start() [<a href='function.session-start'>function.session-start</a>]: Failed to initialize storage module: user (path: ) in C:\Apache2\htdocs\exp\exp.php on line 24
(The error I get looks exactly like the above)
Can someone shed some light on this?
P.S I modified the code and got rid from unnecessary parts, the logic is still the same though.
Thanks in advance guys
I wrote a session class, something along these lines:
Code: Select all
<?php
class session
{
private $db;
public function __construct()
{
// Store a db object within $db
}
public static function _open()
{
return true;
}
public static function _close()
{
return true;
}
public static function _read($id)
{
// Read...
}
public static function _write($id, $data)
{
// Write...
}
public static function _destroy($id)
{
// Destroy...
}
public static function _clean($max)
{
// Clean...
}
}Code: Select all
<?php
include 'my_session_class.php';
$session = new session(); // <- In order to assign the db object into $db
session_set_save_handler('session::_open',
'session::_close',
'session::_read',
'session::_write',
'session::_destroy',
'session::_clean');
session_start(); // This is line 24 where the error occursFatal error: session_start() [<a href='function.session-start'>function.session-start</a>]: Failed to initialize storage module: user (path: ) in C:\Apache2\htdocs\exp\exp.php on line 24
(The error I get looks exactly like the above)
Can someone shed some light on this?
P.S I modified the code and got rid from unnecessary parts, the logic is still the same though.
Thanks in advance guys