* scripts.
*
* ------------------------------------------------------------------------
* USAGE:
* ------------------------------------------------------------------------
* Include this file in your scripts before you call session_start(), you
* don't have to do anything special after that.
*/
$SESS_DBM = "";
$SESS_LIFE = get_cfg_var("session.gc_maxlifetime");
function sess_open($save_path, $session_name) {
global $SESS_DBM;
$SESS_DBM = dbmopen("$save_path/$session_name", "c");
return ($SESS_DBM);
}
function sess_close() {
global $SESS_DBM;
dbmclose($SESS_DBM);
return true;
}
function sess_read($key) {
global $SESS_DBM, $SESS_LIFE;
$var = "";
if ($tmp = dbmfetch($SESS_DBM, $key)) {
$expires_at = substr($tmp, 0, strpos($tmp, "|"));
if ($expires_at > time()) {
$var = substr($tmp, strpos($tmp, "|") + 1);
}
}
return $var;
}
function sess_write($key, $val) {
global $SESS_DBM, $SESS_LIFE;
dbmreplace($SESS_DBM, $key, time() + $SESS_LIFE . "|" . $val);
return true;
}
function sess_destroy($key) {
global $SESS_DBM;
dbmdelete($SESS_DBM, $key);
return true;
}
function sess_gc($maxlifetime) {
global $SESS_DBM;
$now = time();
$key = dbmfirstkey($SESS_DBM);
while ($key) {
if ($tmp = dbmfetch($SESS_DBM, $key)) {
$expires_at = substr($tmp, 0, strpos($tmp, "|"));
if ($now > $expires_at) {
sess_destroy($key);
| 对此文章发表了评论 |
