-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSession.php
executable file
·89 lines (58 loc) · 2.14 KB
/
Session.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require_once 'Zend/Session/SaveHandler/Interface.php';
class Zaape_Session implements Zend_Session_SaveHandler_Interface{
/**
* This is instance of Zaape_Session, which extends Zend_Db_Table and manages the database connection
*
* @var Zaape_Session
*/
private static $sessionData;
private static $thisIsOldSession = false;
private static $originalSessionId = '';
public function open($save_path, $name) {
self::$sessionData = new Model_Session;
return true;
}
public function close(){
return true;
}
public function read($id){
$rows = self::$sessionData->find($id);
$row = $rows->current();
if ($row){
self::$thisIsOldSession = true;
self::$originalSessionId = $id;
return $row->session_data;
}else{
return '';
}
}
public function write($id, $sessionData){
$data = array (
'session_data' => $sessionData,
'modified' => new Zend_Db_Expr('NOW()'),
);
if (self::$thisIsOldSession && self::$originalSessionId != $id){
// session ID is regenerated, so set $thisIsOldSession to false, so we insert new row
self::$thisIsOldSession = false;
}
if (self::$thisIsOldSession){
self::$sessionData->update($data,self::$sessionData->getAdapter()->quoteInto('session_id = ?', $id) );
}else{
//no such session, create new one
$data['session_id'] = $id;
$data['modified'] = new Zend_Db_Expr('NOW()');
self::$sessionData->insert($data);
}
return true;
}
public function destroy($id) {
self::$sessionData->delete(self::$sessionData->getAdapter()->quoteInto('session_id = ?', $id));
return true;
}
public function gc($maxLifetime) {
$maxLifetime = intval($maxLifetime);
self::$sessionData->delete("DATE_ADD(modified, INTERVAL $maxLifetime SECOND) < NOW()");
return true;
}
}