/** * __construct() */ public function __construct() { parent::__construct ();

}

/** * open() * * @param <String> $sSaveP " /> 美女网站视频一区,国产精品一区免费在线,成人福利免费观看

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP 使用MySQL管理Session的回調(diào)函數(shù)詳解

復(fù)制代碼 代碼如下:
<?php
 class MySession extends DBSQL {

  /**
   * __construct()
   */
  public function __construct() {
   parent::__construct ();

  }

  /**
   * open()
   *
   * @param <String> $sSavePath
   * @param <String>$sSessionNames
   *
   * @return <Boolean> true
   */
  public function open($sSavePath, $sSessionName) {
   return true;
  }

  /**
   * close()
   */
  public function close() {
   return true;
  }

  /**
   * read()
   *
   * @param <String> $sSessionId
   * @return <String> 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 <String> $SessionId
   * @param <String> $sSessionData
   *
   * @return <Boolean> 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 <String> $sSessionId
   * @return <Boolean> true
   */
  public function destroy($sSessionId) {
   $sSessionId = addslashes(trim($sSessionId));
   $this->delData($sSessionId, 'F_SessionId', 'tb_session');
   return true;
  }

  /**
   * gc
   *
   * @param <int> $nMaxLifeTime seconds
   *
   * @return <Boolean> true
   */
  public function gc($nMaxLifeTime) {
   $dtExpiredTime = date("Y-m-d H:i:s", time() - $nMaxLifeTime);

   $sSql = "DELETE FROM tb_session WHERE F_SessionUpdated < {$dtExpiredTime}";
   //echo $sSql;
   $this->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技術(shù)PHP 使用MySQL管理Session的回調(diào)函數(shù)詳解,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 汝城县| 金平| 鹤壁市| 百色市| 宜城市| 长宁区| 磐安县| 雅安市| 合山市| 尼勒克县| 富蕴县| 廊坊市| 南京市| 东兰县| 杭锦后旗| 九龙县| 泾源县| 阆中市| 仪陇县| 南靖县| 抚远县| 盘锦市| 本溪| 纳雍县| 海安县| 方正县| 龙胜| 北海市| 永昌县| 秀山| 大冶市| 饶阳县| 安泽县| 许昌市| 女性| 宕昌县| 中江县| 调兵山市| 永定县| 义乌市| 阜平县|