ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
inc.pwassist_session_handler.php
Go to the documentation of this file.
1 <?php
11 /*
12  +-----------------------------------------------------------------------------+
13  | ILIAS open source |
14  +-----------------------------------------------------------------------------+
15  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
16  | |
17  | This program is free software; you can redistribute it and/or |
18  | modify it under the terms of the GNU General Public License |
19  | as published by the Free Software Foundation; either version 2 |
20  | of the License, or (at your option) any later version. |
21  | |
22  | This program is distributed in the hope that it will be useful, |
23  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
24  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25  | GNU General Public License for more details. |
26  | |
27  | You should have received a copy of the GNU General Public License |
28  | along with this program; if not, write to the Free Software |
29  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
30  +-----------------------------------------------------------------------------+
31 */
32 
33 
34 /*
35 * open session, normally a db connection would be opened here, but
36 * we use the standard ilias db connection, so nothing must be done here
37 *
38 * @param string $save_pathDSN information about how to access the database, format:
39 * dbtype(dbsyntax)://username:password@protocol+hostspec/database
40 * eg. mysql://phpsessmgr:topsecret@db.example.com/sessiondb
41 * @param string $name session name [PHPSESSID]
42 */
43 function db_pwassist_session_open($save_path, $name)
44 {
45  return true;
46 }
47 
54 {
55  return true;
56 }
57 
58 /*
59 * Creates a new secure id.
60 *
61 * The secure id has the following characteristics:
62 * - It is unique
63 * - It is a non-uniformly distributed (pseudo) random value
64 * - Only a non-substantial number of bits can be predicted from
65 * previously generated id's.
66 */
68 {
69  // Implementation note: we use the PHP Session id
70  // generation mechanism to create the session id.
71  $old_session_id = session_id();
72  session_regenerate_id();
73  $pwassist_id = session_id();
74  session_id($old_session_id);
75 
76  return $pwassist_id;
77 }
78 
79 /*
80 * Reads data of the session identified by $pwassist_id and returns it as a
81 * associative array. If there is no session with this ID an empty array is
82 * returned
83 *
84 * @param integer $pwassist_id secure id
85 */
86 function db_pwassist_session_read($pwassist_id)
87 {
88  global $ilDB;
89 
90  $q = "SELECT * FROM usr_pwassist ".
91  "WHERE pwassist_id = ".$ilDB->quote($pwassist_id, "text");
92  $r = $ilDB->query($q);
93  $data = $ilDB->fetchAssoc($r);
94 
95  return $data;
96 }
97 
98 /*
99 * Reads data of the session identified by $user_id.
100 * Teturns the data as an associative array.
101 * If there is no session for the specified user_id, an
102 * empty array is returned
103 *
104 * @param integer $user_id user id
105 **/
106 function db_pwassist_session_find($user_id)
107 {
108  global $ilDB;
109 
110  $q = "SELECT * FROM usr_pwassist ".
111  "WHERE user_id = ".$ilDB->quote($user_id, "integer");
112  $r = $ilDB->query($q);
113  $data = $ilDB->fetchAssoc($r);
114 
115  return $data;
116 }
117 
125 function db_pwassist_session_write($pwassist_id, $maxlifetime, $user_id)
126 {
127  global $ilDB;
128 
129  $q = "DELETE FROM usr_pwassist ".
130  "WHERE pwassist_id = ".$ilDB->quote($pwassist_id, "text")." ".
131  "OR user_id = ".$ilDB->quote($user_id,'integer');
132  $ilDB->manipulate($q);
133 
134  $ctime = time();
135  $expires = $ctime + $maxlifetime;
136  $ilDB->manipulateF("INSERT INTO usr_pwassist ".
137  "(pwassist_id, expires, user_id, ctime) ".
138  "VALUES (%s,%s,%s,%s)",
139  array("text", "integer", "integer", "integer"),
140  array($pwassist_id, $expires, $user_id, $ctime));
141 
142  return true;
143 }
144 
150 function db_pwassist_session_destroy($pwassist_id)
151 {
152  global $ilDB;
153 
154  $q = "DELETE FROM usr_pwassist ".
155  "WHERE pwassist_id = ".$ilDB->quote($pwassist_id, "text");
156  $ilDB->manipulate($q);
157 
158  return true;
159 }
160 
161 
166 {
167  global $pear_session_db,$ilDB;
168 
169  $q = "DELETE FROM usr_pwassist ".
170  "WHERE expires < ".$ilDB->quote(time(), "integer");
171  $ilDB->manipulate($q);
172 
173  return true;
174 }
175 ?>