首页 > php教程 > PHP源码 > PHP 使用 session_set_save_handler() 对 Session 进行自定义处理

PHP 使用 session_set_save_handler() 对 Session 进行自定义处理

PHP中文网
发布: 2016-05-25 17:15:58
原创
1068 人浏览过

php代码

/*
Session open (called by session_start( ))
Session close (called at page end)
Session read (called after session_start( ) )
Session write (called when session data is to be written)
Session destroy (called by session_destroy( ) )
Session garbage collect (called randomly)
*/
<?
    function sess_open($sess_path, $sess_name) {
            print "Session opened.\n";
            print "Sess_path: $sess_path\n";
            print "Sess_name: $sess_name\n\n";
            return true;
    }

    function sess_close( ) {
            print "Session closed.\n";
            return true;
    }

    function sess_read($sess_id) {
            print "Session read.\n";
            print "Sess_ID: $sess_id\n";
            return &#39;&#39;;
    }

    function sess_write($sess_id, $data) {
            print "Session value written.\n";
            print "Sess_ID: $sess_id\n";
            print "Data: $data\n\n";
            return true;
    }

    function sess_destroy($sess_id) {
            print "Session destroy called.\n";
            return true;
    }

    function sess_gc($sess_maxlifetime) {
            print "Session garbage collection called.\n";
            print "Sess_maxlifetime: $sess_maxlifetime\n";
            return true;
    }

    session_set_save_handler("sess_open", "sess_close", "sess_read",
                    "sess_write", "sess_destroy", "sess_gc");
    session_start( );

    $_SESSION[&#39;foo&#39;] = "bar";
    print "Some text\n";
    $_SESSION[&#39;baz&#39;] = "wombat";
?>
登录后复制

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板