首页 > 作文

Session保存到数据库的php类分享

更新时间:2023-04-06 12:53:09 阅读: 评论:0

复制代码 代码如下:

<?php

class ssiontodb

{

private $_path = null;

private $_name = null;

private $_pdo = null;

private $_ip = null;

private $_maxlifetime = 0;

public function __construct(pdo $pdo)

{

ssion_t_save_handler(

array(&$this, ‘open’),

array(&$this, ‘clo’),

array(&$this, ‘read’),

array(&$this, R校园笑话大全201316;write’),

array(&$this, ‘destroy’),

array(&$this, ‘gc’)

);

$this->_pdo = $pdo;

$this->_ip = !empty($_rver[‘remote_addr’]) ? $_rver[‘remote_addr’] : null;

$this->_maxlifetime = ini_get(‘ssion.gc_maxlifetime’);

}

public function open($path,$name)

{

return true;2020高考录取通知何时公布

}

public function clo()

{

return true;

}

public function read($id)

{

$sql = ‘lect * from ssion where phpssid = ?’;

$stmt = $this->_pdo->prepare($sql);

$stmt->execute(array($id));

if (!$result = $stmt->fetch(pdo::fetch_assoc)) {

return null;

} elif ($this->_ip != $result[‘client_ip’]) {

return null;

} elif ($result[‘update_time’]+$this->佐藤美和子_maxlifetime < time()){

$this->destroy($id);

return null;

} el {

return汤圆的做法 $result[‘data’];

}

}

public function write($id,$data)

{

$sql = ‘lect * from ssion where phpssid = ?’;

$stmt = $this->_pdo->prepare($sql);

$stmt->execute(array($id));

if ($result = $stmt->fetch(pdo::fetch_assoc)) {

if ($result[‘data’] != $data) {

$sql = ‘update ssion t update_time =? , date = ? whe品牌标语re phpssid = ?’;

$stmt = $this->_pdo->prepare($sql);

$stmt->execute(array(time(), $data, $id));

}

} el {

if (!empty($data)) {

$sql = ‘inrt into ssion (phpssid, update_time, client_ip, data) values (?,?,?,?)’;

$stmt = $this->_pdo->prepare($sql);

$stmt->execute(array($id, time(), $this->_ip, $data));

}

}

return true;

}

public function destroy($id)

{

$sql = ‘delete from ssion where phpssid = ?’;

$stmt = $this->_pdo->prepare($sql);

$stmt->execute(array($id));

return true;

}

public function gc($maxlifetime)

{

$sql = ‘delete from ssion where update_time < ?’;

$stmt = $this->_pdo->prepare($sql);

$stmt->execute(array(time() – $maxlifetime));

return true;

}

}

try{

$pdo = new pdo(‘mysql:host=localhost;dbname=rphp4zf’, ‘root’,’rickyfeng’);

$pdo->tattribute(pdo::attr_errmode, pdo::errmode_exception);

new ssiontodb($pdo);

} catch(pdoexception $e) {

echo ‘error: ‘.$e->getmessage();

}

本文发布于:2023-04-06 12:53:08,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/0f6def0149b6ce0439d0d2bbd6f0f59d.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:Session保存到数据库的php类分享.doc

本文 PDF 下载地址:Session保存到数据库的php类分享.pdf

下一篇:返回列表
标签:代码   汤圆   标语   笑话大全
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图