1 |
<? |
2 |
// ------------------------------------------------------------------------- |
3 |
// $Id: Session.php,v 1.8 2002/12/28 01:17:53 jonen Exp $ |
4 |
// ------------------------------------------------------------------------- |
5 |
// $Log: Session.php,v $ |
6 |
// Revision 1.8 2002/12/28 01:17:53 jonen |
7 |
// - moved 'validate_idle()' to 'presentation.php' cause some problems |
8 |
// with '$site->request->overrideRequestIdentifer()' at class scope |
9 |
// |
10 |
// Revision 1.7 2002/12/13 00:24:03 jonen |
11 |
// - added debug Dumper |
12 |
// |
13 |
// Revision 1.6 2002/12/05 21:46:09 joko |
14 |
// + global $sessionstate (session-variable) |
15 |
// + function get |
16 |
// + function set |
17 |
// |
18 |
// Revision 1.5 2002/12/04 10:13:21 joko |
19 |
// - purged old code in validate_session |
20 |
// |
21 |
// Revision 1.3 2002/12/03 16:13:21 joko |
22 |
// + bugfix with autologout: |
23 |
// + now just setting some message to site_state here |
24 |
// + no direct getlt! (it's a shortcut function) |
25 |
// + $this->site->user->preLogout(1); as autoload mechanism |
26 |
// |
27 |
// Revision 1.2 2002/12/01 22:32:45 joko |
28 |
// + bugfix: wrong object-hierarchy: |
29 |
// use $this->site->user->preLogout and/or $this->site->request->overrideReq... |
30 |
// + documented |
31 |
// |
32 |
// Revision 1.1 2002/11/12 05:42:31 joko |
33 |
// + initial checkin |
34 |
// |
35 |
// ------------------------------------------------------------------------- |
36 |
|
37 |
|
38 |
class Session { |
39 |
|
40 |
//============== session functions============= |
41 |
function &Session() { |
42 |
global $session_cfg; |
43 |
$session_cfg["session_id"] = session_id(); |
44 |
$session_cfg["remote_ip"] = $_SERVER["REMOTE_ADDR"]; |
45 |
$session_cfg["remote_port"] = $_SERVER["REMOTE_PORT"]; |
46 |
$session_cfg["user_agent"] = $_SERVER["HTTP_USER_AGENT"]; |
47 |
$session_cfg["http_referer"] = $_SERVER["HTTP_REFERER"]; |
48 |
$session_cfg["date"] = date('Y-m-d H:i:s', time()); |
49 |
|
50 |
if (session_register_safe('sessionstate')) { |
51 |
} |
52 |
|
53 |
} |
54 |
|
55 |
function start() { |
56 |
// FIXME: global $session_cfg; |
57 |
global $session_cfg; |
58 |
$session_exists = $this->exists($session_cfg["session_id"]); |
59 |
//print Dumper($session_exists); |
60 |
if (!is_array($session_exists)) { |
61 |
$this->add_session($session_cfg); |
62 |
} else { |
63 |
$session_cfg["session_uid"] = $session_exists["session_uid"]; |
64 |
//if ($this->site->user->isLoggedOn()) { |
65 |
//print "val - idle<br>"; |
66 |
//$this->validate_idle(); |
67 |
//} |
68 |
//print "val - session<br>"; |
69 |
//$this->validate_session($session_cfg); |
70 |
} |
71 |
} |
72 |
|
73 |
function validate_session($scfgt) { |
74 |
$this->update_session($scfgt); |
75 |
} |
76 |
|
77 |
function update_session($scfg) { |
78 |
$sql = "UPDATE f_td_sessions SET session_hits=session_hits+1,last_date='$scfg[date]' WHERE session_uid='$scfg[session_uid]'"; |
79 |
$res = send_sql($sql); |
80 |
} |
81 |
|
82 |
function add_session($scfg) { |
83 |
//session_start(); |
84 |
//session_register('user_status_val'); |
85 |
// FIXME: use PEAR here! |
86 |
connectdb(); |
87 |
$sql="INSERT INTO f_td_sessions VALUES ('','$scfg[session_id]','1','$scfg[remote_ip]','$scfg[remote_port]','$scfg[user_agent]','$scfg[http_referer]','$scfg[date]','$scfg[date]')"; |
88 |
$res = send_sql($sql); |
89 |
} |
90 |
|
91 |
function bindUser() { |
92 |
$session_id = session_id(); |
93 |
$session_tm = $this->exists($session_id); |
94 |
$date = date('Y-m-d H:i:s', time()); |
95 |
$sql = "SELECT mid FROM f_map_user_session WHERE user_uid='$site->user->get('oid')' AND last='1'"; |
96 |
if($res = send_sql($sql)) { |
97 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
98 |
//if (!mysql_num_rows($res)>0) { |
99 |
$sql2 = "INSERT INTO f_map_user_session VALUES ('','$this->site->user->get('oid')','$session_tm[session_uid]','$date','','1')"; |
100 |
$res2 = send_sql($sql2); |
101 |
} |
102 |
else { |
103 |
//print_r($row); |
104 |
$sql3 = "Update f_map_user_session SET last='0' WHERE mid='$row[mid]'"; |
105 |
$res3 = send_sql($sql3); |
106 |
$sql4 = "INSERT INTO f_map_user_session VALUES ('','$this->site->user->get('oid')','$session_tm[session_uid]','$date','','1')"; |
107 |
$res4 = send_sql($sql4); |
108 |
} |
109 |
} |
110 |
|
111 |
function exists($session_id) { |
112 |
// check if sessionID exists |
113 |
connectdb(); |
114 |
$sql_exists = "SELECT session_uid,session_id FROM f_td_sessions WHERE session_id='$session_id'"; |
115 |
$res_exists = send_sql($sql_exists); |
116 |
if (!$res_exists || !mysql_num_rows($res_exists) > 0) { |
117 |
return 0; |
118 |
} |
119 |
else { |
120 |
$row = mysql_fetch_array($res_exists, MYSQL_ASSOC); |
121 |
return $row; |
122 |
} |
123 |
} |
124 |
|
125 |
|
126 |
|
127 |
function get($attribute) { |
128 |
global $sessionstate; |
129 |
//print "session - get: " . Dumper($sessionstate) . "<br>"; |
130 |
return $sessionstate[$attribute]; |
131 |
} |
132 |
|
133 |
function set($attribute, $value) { |
134 |
global $sessionstate; |
135 |
//print "val: " . Dumper($value) . "<br>"; |
136 |
$sessionstate[$attribute] = $value; |
137 |
//print "session - set: " . Dumper($sessionstate) . "<br>"; |
138 |
} |
139 |
|
140 |
} |
141 |
|
142 |
?> |