1+ <?php
2+
3+ /*
4+ Copyright (c) 2010, Till Brehm, projektfarm Gmbh
5+ All rights reserved.
6+
7+ Redistribution and use in source and binary forms, with or without modification,
8+ are permitted provided that the following conditions are met:
9+
10+ * Redistributions of source code must retain the above copyright notice,
11+ this list of conditions and the following disclaimer.
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ this list of conditions and the following disclaimer in the documentation
14+ and/or other materials provided with the distribution.
15+ * Neither the name of ISPConfig nor the names of its contributors
16+ may be used to endorse or promote products derived from this software without
17+ specific prior written permission.
18+
19+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+ IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+ */
30+
31+ class session {
32+
33+ private $ session_array = array ();
34+ private $ db ;
35+
36+ function __construct () {
37+ $ this ->db = new db ;
38+ }
39+
40+ function open ($ save_path , $ session_name ) {
41+ return true ;
42+ }
43+
44+ function close () {
45+ if (!empty ($ this ->fieldarray )) {
46+ $ result = $ this ->gc (ini_get ('session.gc_maxlifetime ' ));
47+ return $ result ;
48+ }
49+ return false ;
50+ }
51+
52+ function read ($ session_id ) {
53+
54+ $ rec = $ this ->db ->queryOneRecord ("SELECT * FROM sys_session WHERE session_id = ' " .$ this ->db ->quote ($ session_id )."' " );
55+
56+ if (is_array ($ rec )) {
57+ $ this ->session_array = $ rec ;
58+ return $ this ->session_array ['session_data ' ];
59+ } else {
60+ return '' ;
61+ }
62+ }
63+
64+ function write ($ session_id , $ session_data ) {
65+
66+ if (!empty ($ this ->session_array ) && $ this ->session_array ['session_id ' ] != $ session_id ) {
67+ $ this ->session_array = array ();
68+ }
69+
70+ if ($ this ->session_array ['session_id ' ] == '' ) {
71+ $ session_id = $ this ->db ->quote ($ session_id );
72+ $ date_created = date ('Y-m-d H:i:s ' );
73+ $ last_updated = date ('Y-m-d H:i:s ' );
74+ $ session_data = $ this ->db ->quote ($ session_data );
75+ $ sql = "INSERT INTO sys_session (session_id,date_created,last_updated,session_data) VALUES (' $ session_id',' $ date_created',' $ last_updated',' $ session_data') " ;
76+ $ this ->db ->query ($ sql );
77+ } else {
78+ $ session_id = $ this ->db ->quote ($ session_id );
79+ $ last_updated = date ('Y-m-d H:i:s ' );
80+ $ session_data = $ this ->db ->quote ($ session_data );
81+ $ sql = "UPDATE sys_session SET last_updated = ' $ last_updated', session_data = ' $ session_data' WHERE session_id = ' $ session_id' " ;
82+ $ this ->db ->query ($ sql );
83+ }
84+
85+ return true ;
86+ }
87+
88+ function destroy ($ session_id ) {
89+
90+ $ session_id = $ this ->db ->quote ($ session_id );
91+ $ sql = "DELETE FROM sys_session WHERE session_id = ' $ session_id' " ;
92+ $ this ->db ->query ($ sql );
93+
94+ return true ;
95+ }
96+
97+ function gc ($ max_lifetime ) {
98+
99+ $ real_now = date ('Y-m-d H:i:s ' );
100+ $ dt1 = strtotime ("$ real_now - $ max_lifetime seconds " );
101+ $ dt2 = date ('Y-m-d H:i:s ' , $ dt1 );
102+
103+ $ sql = "DELETE FROM sys_session WHERE last_updated < ' $ dt2' " ;
104+ $ this ->db ->query ($ sql );
105+
106+ return true ;
107+
108+ }
109+
110+ function __destruct () {
111+ @session_write_close ();
112+
113+ }
114+ }
115+
116+ ?>
0 commit comments