国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

輕松實(shí)現(xiàn)session的mysql處理

2024-07-24 12:31:24
字體:
供稿:網(wǎng)友
     輕松實(shí)現(xiàn)session的mysql處理 (轉(zhuǎn))[@more@]
     通常,session都是保存在臨時(shí)文件里的,但是,要是把它保存在數(shù)據(jù)庫里,就會給我們帶來很多好處,比如統(tǒng)計(jì)在線人數(shù)之類的。廢話不說了,看程序:
 
     include("db_mysql.inc");
 
     function open ($save_path, $session_name) {
  global $db,$REMOTE_ADDR;
  $db->query("delete from Sessions where SessionLast1 hour)");
  if($db->query("select * from Sessions where SessionID='".session_id()."'")
&& $arry=$db->fetch_array())
  $db->query("update Sessions set SessionLast=NOW() where
SessionID='".session_id()."'");
  else $db->query("insert into Sessions set
SessionID='".session_id()."',SessionName='$REMOTE_ADDR',SessionLast='NOW()'"
);
  return(true);
}
 
function close()
 
  return true;
}
 
     function read ($id) {
  global $db;
  if(!$db->query("select SessionID from Sessions where SessionID='$id'")
|| $db->num_rows()<=0)return false;
  $SQL="select SessionData from Sessions where SessionID='$id'";
  $db->query($SQL);
  list($sess_data)=$db->fetch_row();
  return($sess_data);
}
 
function write ($id, $sess_data) {
  global $db;
  if(!$db->query("select SessionID from Sessions where SessionID='$id'") ||
$db->num_rows()<=0)return false;
  if($db->query("update Sessions set
SessionData='$sess_data',SessionLast=NOW() where SessionID='$id'"))
  return true;
  else return false;
}
 
function destroy ($id) {
  global $db;
  $db->query("delete from Sessions where SessionID='$id'");
}
 
function gc ($maxlifetime) {
  return true;
}
 
session_set_save_handler ("open", "close", "read", "write", "destroy","gc");
 
session_start();
 
?>
注:
數(shù)據(jù)表:Sessions
CREATE TABLE Sessions (
  SessionID varchar(50) NOT NULL,
  SessionName varchar(50) NOT NULL,
  SessionData blob,
  SessionLast datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  PRIMARY KEY (SessionID)
);

(編輯:武林網(wǎng))

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 城口县| 吐鲁番市| 兴业县| 昌江| 新疆| 五莲县| 江北区| 桂东县| 东丽区| 潼关县| 隆化县| 政和县| 修文县| 兴隆县| 滦平县| 望谟县| 崇仁县| 利辛县| 清徐县| 泰兴市| 砀山县| 广平县| 陕西省| 合肥市| 清涧县| 山西省| 会东县| 盐山县| 平潭县| 澄迈县| 务川| 陵川县| 阿瓦提县| 子洲县| 垦利县| 台湾省| 东莞市| 华池县| 绥棱县| 阳西县| 吉木萨尔县|