zhphp framework (二十三) 文件缓存

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: 张华
 * Date: 14-3-8
 * Time: 下午12:21
 * QQ: 746502560@qq.com
 * To change this template use File | Settings | File Templates.
 */
class fileSession extends  session {
    private $_expiry=3600;#默认的有效期
    private $_domain;#有效域名
    private  $_prefix;#有效前缀
    public  function  __construct(){
        $this->_domain=isset($GLOBALS['_SERVER']['HTTP_HOST'])?$GLOBALS['_SERVER']['HTTP_HOST']:$_SERVER['HTTP_HOST'];
        $this->_prefix=sha1(config::readConfig('sesssion','key_token'));
        ini_set('session.use_trans_id', 0);
        ini_set('session.gc_maxlifetime', $this->_expiry);
        ini_set('session.use_cookie', 1);
        ini_set('session.cookie_path', APP_PATH.'data/session/');
        ini_set('session.cookie_domain', $this->_domain);
     }

    public function  addSession($key, $value)
    {
        // TODO: Implement addSession() method.
      return  $_SESSION[$this->_prefix][$key] = $value;
    }

    public function  setSession($key, $value)
    {
        // TODO: Implement setSession() method.
       return is_null($this->getSession($key))?$_SESSION[$this->_prefix][$key] = $value:$_SESSION[$this->_prefix][$key] = $value;

     }

    public function  getSession($key)
    {
        // TODO: Implement getSession() method.
        return (isset($_SESSION[$this->_prefix][$key]) ? $_SESSION[$this->_prefix][$key] : null);
    }

    public function  getAllSession()
    {
        // TODO: Implement getAllSession() method.
        return $_SESSION['$this->prefix'];
    }

    public function  unsetSession()
    {
        // TODO: Implement unsetSession() method.{
           $session_vars = func_get_args();
           foreach($session_vars as $session_var) {
               if($this->getSession($session_var)||is_array(getSession($session_var))) {
                   $_SESSION[$this->_prefix][$session_var]=null;
                   unset($_SESSION[$this->_prefix][$session_var]);
               }
           }
     }

    public function  unsetAllSession()
    {
        // TODO: Implement unsetAllSession() method.
        $_SESSION=array();
        session_destroy();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值