I am trying to set up a user login/logout system using php and mysql. I have found some documentation on the subject here: http://phpmaster.com/writing-custom-session-handlers/. I am trying to follow along with it (I have also been pulling from other sources too - but this is the main one).
Here is some of my code from "my_session_handler.php":
class MySessionHandler implements SessionHandlerInterface {
private $path = session_save_path();
private $name = session_name();
private $sessionId = session_id();
function open($path, $name) {
$db = new PDO("mysql:host=localhost;dbname=itit", "root", "bonjour3");
$sql = "INSERT INTO session SET session_id =" . $db->quote($sessionId) . ", session_data = '' ON DUPLICATE KEY UPDATE session_lastaccesstime = NOW()";
$db->query($sql);
...
My question is, where are the "$path" and "$name" variables coming from in the example I cited above? I declared them as private variables and used some functions to do what I am thinking needs to be done. But on the website that I am following along with - neither of these variables get declared - along with $sessionId. I see that the read function returns $data. So I used it in the "write" function like this:
function write($sessionId, this.read($sessionId)) {
$db = new PDO("mysql:host=localhost;dbname=itit", "root", "bonjour3");
$sql = "INSERT INTO session SET session_id =" . $db->quote($sessionId) . ", session_data =" . $db->quote($data) . " ON DUPLICATE KEY UPDATE session_data =" . $db->quote($data);
$db->query($sql)
}
Am I doing this right?
These parameters are used by the default session save handler, which saves the session data in files. They come from the php.ini
file, and are used to form the filenames. They're supplied to your handler when PHP calls the open()
method.
If you're writing a custom handler, you can ignore them, as the code on that web page does.