session_set_save_handler()
Posted: Tue May 27, 2003 10:36 am
Hi there, i am building my own handler because i need my sessions to be stored in the database so that i can also compare them with cookies and what not. Though I already have something, it is very basic and i have not tested it yet, i was wondering if someone has already done one and/pr would give me some direction on how to make a good one.
I am closely following the manual's technique, that is:
And i have replaced most file read write stuff with mysql_query()
I doubt that what i got so far is even worth reading so i was hoping to get insight or even some link to somewhere that has previously helped some to achieve this.
here is my mysql table structure, in short:
sess_id
sess_time timestamp(14)
user
data
thx
I am closely following the manual's technique, that is:
Code: Select all
<?php
function open ($save_path, $session_name) {
global $sess_save_path, $sess_session_name;
$sess_save_path = $save_path;
$sess_session_name = $session_name;
return(true);
}
function close() {
return(true);
}
function read ($id) {
global $sess_save_path, $sess_session_name;
$sess_file = "$sess_save_path/sess_$id";
if ($fp = @fopen($sess_file, "r")) {
$sess_data = fread($fp, filesize($sess_file));
return($sess_data);
} else {
return(""); // Must return "" here.
}
}
function write ($id, $sess_data) {
global $sess_save_path, $sess_session_name;
$sess_file = "$sess_save_path/sess_$id";
if ($fp = @fopen($sess_file, "w")) {
return(fwrite($fp, $sess_data));
} else {
return(false);
}
}
function destroy ($id) {
global $sess_save_path, $sess_session_name;
$sess_file = "$sess_save_path/sess_$id";
return(@unlink($sess_file));
}
/*********************************************
* WARNING - You will need to implement some *
* sort of garbage collection routine here. *
*********************************************/
function gc ($maxlifetime) {
return true;
}
session_set_save_handler ("open", "close", "read", "write", "destroy", "gc");
session_start();
// proceed to use sessions normally
?>I doubt that what i got so far is even worth reading so i was hoping to get insight or even some link to somewhere that has previously helped some to achieve this.
here is my mysql table structure, in short:
sess_id
sess_time timestamp(14)
user
data
thx