24 |
var $max_duration = 43200; |
var $max_duration = 43200; |
25 |
|
|
26 |
// Database variables |
// Database variables |
27 |
var $db_session = "libsession"; |
#var $session_dsn = 'mysql://libsession:libsessionpw@localhost/libsession'; |
28 |
var $db_session_srv = "localhost"; |
var $session_dsn = 'pgsql://dpavlin@/libdata'; |
|
var $db_session_usr = "libsession"; |
|
|
var $db_session_pwd = "libsessionpw"; |
|
29 |
|
|
30 |
|
|
31 |
/********************************************************** |
/********************************************************** |
39 |
**********************************************************/ |
**********************************************************/ |
40 |
function sessionClass($duration, $session_id, $staff_account) { |
function sessionClass($duration, $session_id, $staff_account) { |
41 |
|
|
42 |
// Set the database connection variables |
// Set the database connection variables |
43 |
$this->con_session = @mysql_connect ( $this->db_session_srv, $this->db_session_usr, $this->db_session_pwd ) |
global $dsn_options; |
44 |
or die ( "ERROR: Could not connect to database server!" ); |
$this->con_session =& DB::connect($this->session_dsn, $dsn_options); |
45 |
$this->result_session = mysql_select_db ( $this->db_session, $this->con_session ) |
if (DB::isError($db)) { |
46 |
or die ( "ERROR: Could not connect to database!" ); |
# XXX remove this! |
47 |
|
print $db->getDebugInfo(); |
48 |
|
|
49 |
|
die($db->getMessage()); |
50 |
|
} |
51 |
|
|
52 |
// Fetch user ip |
// Fetch user ip |
53 |
$user_ip = $GLOBALS["REMOTE_ADDR"]; |
$user_ip = $GLOBALS["REMOTE_ADDR"]; |
90 |
$time_human = $year . "-" . $mon . "-" . $mday . " " . $hours . ":" . $minutes . ":" . $seconds; |
$time_human = $year . "-" . $mon . "-" . $mday . " " . $hours . ":" . $minutes . ":" . $seconds; |
91 |
|
|
92 |
// Build the SQL line to insert it into the database |
// Build the SQL line to insert it into the database |
93 |
$sql = "INSERT INTO session (staff_account, user_ip, session_id, time_human, time_unix, time_expire) VALUES ('" |
$sql = "INSERT INTO session (staff_account, user_ip, session_id, time_human, time_unix, time_expire) |
94 |
. $staff_account |
VALUES (?, ?, ?, ?, ?, ?)"; |
|
. "', '" |
|
|
. $user_ip |
|
|
. "', '" |
|
|
. $session_id |
|
|
. "', '" |
|
|
. $time_human |
|
|
. "', '" |
|
|
. $time_unix |
|
|
. "', '" |
|
|
. $time_expire |
|
|
. "')"; |
|
95 |
|
|
96 |
// mysql_query ("LOCK TABLE session WRITE", $this->con_session); |
// xx_query ("LOCK TABLE session WRITE", $this->con_session); |
97 |
if (!mysql_query($sql, $this->con_session)){ |
if (!xx_prepare_execute($sql, |
98 |
mysql_query ("UNLOCK TABLES", $this->con_session); |
$staff_account, |
99 |
|
$user_ip, |
100 |
|
$session_id, |
101 |
|
$time_human, |
102 |
|
$time_unix, |
103 |
|
$time_expire)) { |
104 |
|
xx_query ("UNLOCK TABLES", $this->con_session); |
105 |
$this->bailout(); |
$this->bailout(); |
106 |
} |
} |
107 |
else { |
else { |
108 |
mysql_query("UNLOCK TABLES", $this->con_session); |
xx_query("UNLOCK TABLES", $this->con_session); |
109 |
} |
} |
110 |
|
|
111 |
|
|
186 |
|
|
187 |
// The SQL |
// The SQL |
188 |
$sql = "SELECT * FROM session where session_id = '" . $hash . "'"; |
$sql = "SELECT * FROM session where session_id = '" . $hash . "'"; |
189 |
$rs = mysql_query($sql, $con_session); |
$rs = xx_query($sql, $con_session); |
190 |
$duplicate = mysql_num_rows($rs); |
$duplicate = xx_num_rows($rs); |
191 |
if ($duplicate > 0) { |
if ($duplicate > 0) { |
192 |
$duplicate = 1; |
$duplicate = 1; |
193 |
$hash = "0"; |
$hash = "0"; |
226 |
. "' AND user_ip = '" |
. "' AND user_ip = '" |
227 |
. $user_ip |
. $user_ip |
228 |
."'"; |
."'"; |
229 |
$rs = mysql_query($sql, $con_session); |
$rs = xx_query($sql, $con_session); |
230 |
$valid = mysql_num_rows($rs); |
$valid = xx_num_rows($rs); |
231 |
$row = mysql_fetch_array ($rs); |
$row = xx_fetch_array ($rs); |
232 |
$time_human = $row["time_human"]; |
$time_human = $row["time_human"]; |
233 |
$time_unix = $row["time_unix"]; |
$time_unix = $row["time_unix"]; |
234 |
$time_expire = $row["time_expire"]; |
$time_expire = $row["time_expire"]; |
289 |
. $user_ip |
. $user_ip |
290 |
. "'"; |
. "'"; |
291 |
|
|
292 |
//mysql_query ("LOCK TABLE session WRITE", $con_session); |
//xx_query ("LOCK TABLE session WRITE", $con_session); |
293 |
if (!mysql_query($sql, $con_session)){ |
if (!xx_query($sql, $con_session)){ |
294 |
mysql_query ("UNLOCK TABLES", $con_session); |
xx_query ("UNLOCK TABLES", $con_session); |
295 |
$this->bailout(); |
$this->bailout(); |
296 |
} |
} |
297 |
else { |
else { |
298 |
mysql_query("UNLOCK TABLES", $con_session); |
xx_query("UNLOCK TABLES", $con_session); |
299 |
$this->setProperties($session_id, $user_ip); |
$this->setProperties($session_id, $user_ip); |
300 |
} |
} |
301 |
|
|
326 |
|
|
327 |
$sql = "DELETE FROM session where time_expire < " . $time_unix; |
$sql = "DELETE FROM session where time_expire < " . $time_unix; |
328 |
|
|
329 |
if (!mysql_query($sql, $con_session)){ |
if (!xx_query($sql, $con_session)){ |
330 |
sql_err($con_session); |
sql_err($con_session); |
331 |
mysql_query ("UNLOCK TABLES", $con_session); |
xx_query ("UNLOCK TABLES", $con_session); |
332 |
bailout(); |
bailout(); |
333 |
} |
} |
334 |
else { |
else { |
335 |
mysql_query("UNLOCK TABLES", $con_session); |
xx_query("UNLOCK TABLES", $con_session); |
336 |
} |
} |
337 |
} // end of function |
} // end of function |
338 |
} // end of class |
} // end of class |