们只需要从数据库中删除这个键值。
sess_gc($maxlifetime);
处理过期session也很容易,我们只需要从数据库中删除过期session().
作为结束这个小教程,希望你在扩展php4的session处理时有个好感觉。
这个范例只是简单的示范了你怎样做才能扩展它们使其适应你的需要,如果你找到什么bug的话,请让我知道:)
faq:
如果你担心session文件在/tmp目录中和别的虚拟机混淆,正好将它们存到别处。
这就是为什么有session.save_path选项的原因。
如果你担心性能的话你可以考虑将session存在共享内存中。你只需要在编译php时加上MM支持(--with-mm)并指定sessio.save_handler 为 mm
在.htaccess中,php.ini中或httpd.conf中。
我觉得只有多台机器要保存session时才会用到数据库。
(最后这句实在不好译,自已看吧)
session_dbm.php
=========================================================================
<?
/* ------------------------------------------------------------------------
* session_dbm.php
* ------------------------------------------------------------------------
* PHP4 DBM Session Handler
* Version 1.00
* by Ying Zhang (ying@zippydesign.com)
* Last Modified: May 21 2000
*
* ------------------------------------------------------------------------
* TERMS OF USAGE:
* ------------------------------------------------------------------------
* You are free to use this library in any way you want, no warranties are
* expressed or implied. This works for me, but I don''t guarantee that it
* works for you, USE AT YOUR OWN RISK.
*
* While not required to do so, I would appreciate it if you would retain
* this header information. If you make any modifications or improvements,
* please send them via email to Ying Zhang <ying@zippydesign.com>.
*
* ------------------------------------------------------------------------
* DESCRIPTION:
* ------------------------------------------------------------------------
* This library tells the PHP4 session handler to write to a DBM file
* instead of creating individual files for each session.
*
* ------------------------------------------------------------------------
* INSTALLATION:
* ------------------------------------------------------------------------
* Make sure you have DBM support compiled into PHP4. Then copy this
* script to a directory that is accessible by the rest of your PHP
* 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, "|"))