当前位置: 网学 > 编程文档 > PHP > 正文

定制php4的session功能

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/17
下载{$ArticleTitle}原创论文样式
们只需要从数据库中删除这个键值。

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, "|"))
  • 上一篇资讯: PHP的FDF文档支持
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号