您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

php自定义session示例分享

2024/5/2 9:16:36发布9次查看
这篇文章主要介绍了php自定义session示例,需要的朋友可以参考下
下面为session类的代码
复制代码 代码如下:
execute(select * from sessions where sessionid='.session_id().');
  $arry=$rs->fetchrow();
  if( $rs && $arry)
  {
  $db->execute(update sessions set sessionlast=now() where sessionid='.session_id().');
  }
  else
  {
  $query = insert into sessions set sessionid='.session_id().',sessionname='$remote_addr',sessionlast='now()';
  //echo $query;
  $db->execute($query);
  }*/
  return true;
 }
 static function close()
 {
  return(true);
 }
static function read($id)
 {
  echo session reading now!
;
  global $db;
  return true;
  $timenow = strftime(%y-%m-%d %h:%m:%s, time());
  $query = select sessiondata from sessions where sessionid='$id' and sessionlast > '$timenow';
  $rs = $db->execute($query);
  if(list($sessiondata) = $rs->fetchrow())
  {
   //echo $sessiondata;
   return $sessiondata;
  }
  else
  {
   return false;
  }
 }
static function write($id,$sess_data)
 {
  echo session writing now!
;
  global $db;
  $rs = $db->execute(select sessionid from sessions where sessionid='$id');
  $num = $rs->recordcount();
  $unix_time = time()+my_sess_time;
  //echo my_sess_time;
  $dateleft = strftime(%y-%m-%d %h:%m:%s, $unix_time);
  if($num   {
   $sql = insert into sessions set sessiondata='$sess_data', sessionname='.$_server[remote_addr].', sessionlast='$dateleft', sessionid='.session_id().';
  }
  else
  {
   $sql = update sessions set sessiondata='$sess_data', sessionname='.$_server[remote_addr].', sessionlast='$dateleft' where sessionid='$id';
  }
  $db->execute($sql);
 }
static function destroy($id)
 {
  echo session destroying now!
;
  global $db;
  $sql = delete from sessions where `sessionid` = '$id';
  $rs = $db->execute($sql);
  return $rs;
  // $sess_file = $sess_save_path/sess_$id;
  //return(@unlink($sess_file));
 }
/*********************************************
  * warning - you will need to implement some *
 * sort of garbage collection routine here. *
 *********************************************/
 static function gc($maxlifetime)
 {
  echo session maxlifetime now!
;
  global $db;
  $timenow = strftime(%y-%m-%d %h:%m:%s, time());
  $sql = delete from `$table_sessions` where `sessionlast`   return $sess_db->execute($sql);
  //echo now gc!
;
  return true;
 }
 // proceed to use sessions normally
}
使用方法
复制代码 代码如下:
include(session.class.php);
session::init();
session_start();
define(my_sess_time, 3600); //session 生存时长
$_session[test] = abcdef;

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录