找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 286|回复: 0
打印 上一主题 下一主题

PHP 使用MySQL管理Session的回调函数详解

[复制链接]

2536

主题

2536

帖子

7532

积分

论坛元老

Rank: 8Rank: 8

积分
7532
跳转到指定楼层
楼主
发表于 2018-2-14 08:16:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            [U]复制代码[/U] 代码如下:
$sSavePath
   * @param $sSessionNames
   *
   * @return [B] true
   */
  public function open($sSavePath, $sSessionName) {
   return true;
  }
  /**
   * close()
   */
  public function close() {
   return true;
  }
  /**
   * read()
   *
   * @param  $sSessionId
   * @return  Session data or null on error...
   */
  public function read($sSessionId) {
   $sSessionId = addslashes(trim($sSessionId));
   $sSql = "SELECT * FROM tb_session WHERE F_SessionId = '{$sSessionId}'";
   //echo $sSql;
   if(false != ($result = $this->select($sSql))) {
    //var_dump($result[0]['F_SessionData']);
    return $result[0]['F_SessionData'];
   } else {
    return '';
   }
  }
  /**
   * write()
   *
   * @param  $SessionId
   * @param  $sSessionData
   *
   * @return [B] true or false
   */
  public function write($sSessionId, $sSessionData) {
   $arrSession = array();
   $arrSession['F_SessionId'] = addslashes(trim($sSessionId));
   $arrSession['F_SessionData'] = addslashes($sSessionData);
   $arrSession['F_SessionCreated'] = date("Y-m-d H:i:s");
   $arrSession['F_SessionUpdated'] = date("Y-m-d H:i:s", time() + 1440);
   // 新session及更新的session
   if (false != ($result = $this->insertData('tb_session', $arrSession))) {
    return true;
   } else {
    $arrUpdateSession = array();
    $arrUpdateSession['F_SessionData'] = addslashes($sSessionData);
    $arrUpdateSession['F_SessionUpdated'] = date("Y-m-d H:i:s", time() + 1440);
    if (false != ($result = $this->updateData('tb_session', "'".addslashes($sSessionId)."'", 'F_SessionId', $arrUpdateSession))) {
     return true;
    } else {
     return false;
    }
   }
  }
  /**
   * destroy()
   *
   * @param  $sSessionId
   * @return [B] true
   */
  public function destroy($sSessionId) {
   $sSessionId = addslashes(trim($sSessionId));
   $this->delData($sSessionId, 'F_SessionId', 'tb_session');
   return true;
  }
  /**
   * gc
   *
   * @param $nMaxLifeTime seconds
   *
   * @return [B] true
   */
  public function gc($nMaxLifeTime) {
   $dtExpiredTime = date("Y-m-d H:i:s", time() - $nMaxLifeTime);
   $sSql = "DELETE FROM tb_session WHERE F_SessionUpdated delete($sSql);
   return true;
  }
  /**
   * __desctruct()
   *
   */
  function __destruct() {
   // ensure session data is written out before classes are destroyed
      // (see http://bugs.php.net/bug.php?id=33772 for details)
         @session_write_close();
     } // __destruct
}
?>
            
            
您可能感兴趣的文章:
  • PHP 的异常处理、错误的抛出及回调函数等面向对象的错误处理方法
  • PHP将回调函数作用到给定数组单元的方法
  • php微信浏览器分享设置以及回调详解
  • PHP Callable强制指定回调类型的方法
  • PHP中call_user_func_array回调函数的用法示例
  • PHP回调函数与匿名函数实例详解
  • PHP编程之微信公众平台企业号验证接口示例【回调操作】
  • PHP回调函数概念与用法实例分析
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端