MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
msession.class
Ir para a documentação deste ficheiro.
1
<?php
6
class
MSession
extends
MService
7
{
11
var
$id
=
""
;
12
16
var
$name
=
""
;
17
21
var
$cookie_path
=
'/'
;
22
26
var
$cookiename
=
"PHPSESSID"
;
27
31
var
$lifetime
= 0;
32
36
var
$cookie_domain
=
''
;
37
41
var
$mode
=
"cookie"
; ## We propagate session IDs with cookies
42
46
var
$fallback_mode
=
"cookie"
; ##
if
fallback_mode is also
'ccokie'
47
48
## we enforce session.use_only_cookie
52
var
$trans_id_enabled
=
false
;
53
57
var
$allowcache
=
'nocache'
;
58
62
private
$db = NULL;
63
67
private
$host;
68
78
function
__construct
(
$name
=
''
)
79
{
80
parent::__construct();
81
$this->
SetName
($name);
82
}
83
93
function
start
($sid = NULL)
94
{
95
$ok =
true
;
96
try
97
{
98
if
($this->mode ==
"cookie"
&& $this->fallback_mode ==
"cookie"
)
99
{
100
ini_set(
"session.use_only_cookie"
,
"1"
);
101
}
102
103
$this->
put_headers
();
104
105
if
($sid != NULL)
106
{
107
$this->
SetId
($sid);
108
}
109
110
if
($this->manager->GetConf(
'session.handler'
) ==
'db'
)
111
{
112
$this->db = $this->manager->GetDatabase(
'miolo'
);
113
$this->host = $_SERVER[
'REMOTE_ADDR'
];
114
session_set_save_handler(
115
array($this,
'open'
),
116
array($this,
'close'
),
117
array($this,
'read'
),
118
array($this,
'write'
),
119
array($this,
'delete'
),
120
array($this,
'garbage'
)
121
);
122
}
123
124
session_start();
125
$this->
id
= session_id();
126
127
if
(!isset($_SESSION[
'timestamp'
]))
128
{
129
$_SESSION[
'timestamp'
] = time();
130
}
131
132
}
133
catch
(
EMioloException
$e )
134
{
135
throw
$e;
136
}
137
138
/* temporarily not available
139
if ( MUtil::getBooleanValue($this->manager->getConf('options.loading.show')) )
140
{
141
echo '<div id="loading">';
142
echo ' <div id="message">';
143
echo _M('Loading...');
144
echo ' </div>';
145
flush();
146
}
147
*/
148
149
return
$ok;
150
}
151
159
function
destroy
()
160
{
161
// Unset all of the session variables.
162
$_SESSION = array();
163
// If it's desired to kill the session, also delete the session cookie.
164
// Note: This will destroy the session, and not just the session data!
165
if
(isset($_COOKIE[session_name()]))
166
{
167
setcookie(session_name(),
''
, time()-42000,
'/'
);
168
}
169
// Finally, destroy the session.
170
session_destroy();
171
}
172
180
function
checkTimeout
()
181
{
182
$timestamp = time();
183
$difftime = $timestamp - $_SESSION[
'timestamp'
];
184
$this->timeout = ($difftime > ($this->manager->getConf(
'session.timeout'
) * 60));
185
$_SESSION[
'timestamp'
] = $timestamp;
186
if
($this->timeout)
187
{
188
$this->
destroy
();
189
throw
new
ETimeOutException
();
190
}
191
}
192
203
function
SetName
(
$name
=
''
)
204
{
205
if
(
$name
!=
''
)
206
{
207
$name
= (
""
==
$this->cookiename
) ?
'MIOLOSESSID'
:
$this->cookiename
;
208
$name
= (string)
$name
;
209
210
// Só seta o nome da sessão quando ela não estiver ativa.
211
if
(session_status() == PHP_SESSION_NONE) session_name (
$name
);
212
213
$this->name =
$name
;
214
}
215
return
$this->name
;
216
}
217
228
function
SetId
($sid =
''
)
229
{
230
if
($sid !=
''
)
231
{
232
$sid = (string)$sid;
233
$this->
id
= session_id($sid);
234
}
235
return
$this->id
;
236
}
237
245
function
GetId
()
246
{
247
return
$this->id
;
248
}
249
259
function
register
($var_names)
260
{
261
if
(!is_array($var_names))
262
{
263
// spaces spoil everything
264
$var_names = trim($var_names);
265
$var_names = explode(
","
, $var_names);
266
}
267
268
foreach
($var_names as $key => $value)
269
{
270
global $$value;
271
$_SESSION[$value] = $$value;
272
}
273
}
274
284
function
isRegistered
($var_name)
285
{
286
$var_name = trim($var_name);
// to be sure
287
return
isset($_SESSION[$var_name]);
288
}
289
299
function
unregister
($var_names)
300
{
301
$ok =
true
;
302
303
foreach
(explode(
','
, $var_names)as $var_name)
304
{
305
$var_name = trim($var_name);
306
$_SESSION[$var_name] = NULL;
307
}
308
309
return
$ok;
310
}
311
321
function
getValue
($var_name)
322
{
323
$var_name = trim($var_name);
// to be sure
324
return
(isset($_SESSION[$var_name])) ? $_SESSION[$var_name] : NULL;
325
}
326
336
function
get
($var_name)
337
{
338
return
$this->
getValue
($var_name);
339
}
340
351
function
setValue
($var_name, $value)
352
{
353
$var_name = trim($var_name);
// to be sure
354
$_SESSION[$var_name] = $value;
355
}
356
367
function
set
($var_name, $value)
368
{
369
$this->
setValue
($var_name, $value);
370
}
371
379
function
freeze
()
380
{
381
session_commit();
382
}
383
391
function
put_headers
()
392
{
393
# set session.cache_limiter corresponding to $this->allowcache.
394
switch
($this->allowcache)
395
{
396
case
"passive"
:
397
case
"public"
:
398
session_cache_limiter(
"public"
);
399
break
;
400
case
"private"
:
401
session_cache_limiter(
"private"
);
402
break
;
403
default
:
404
session_cache_limiter(
"nocache"
);
405
break
;
406
}
407
}
408
409
// db methods
410
418
function
open
()
419
{
420
return
TRUE;
421
}
422
430
function
close
()
431
{
432
$this->db = NULL;
433
return
TRUE;
434
}
435
445
function
read
(
$id
)
446
{
447
$sql =
new
sql
(
'sessiondata'
,
'miolo_session'
,
"(sid=?) and (tsout='')"
);
448
$sql->SetParameters(
$id
);
449
$query = $this->db->GetQuery($sql);
450
451
if
(!$query->eof())
452
{
453
$data = stripslashes($query->fields(
'sessiondata'
));
454
}
455
456
return
$data;
457
}
458
469
function
write
(
$id
, $data)
470
{
471
$iduser = $this->manager->auth->iduser;
472
$sql =
new
sql
(
'idsession,sid,sessiondata'
,
'miolo_session'
,
"(sid=?) and (tsout='')"
);
473
$sql->SetParameters(
$id
);
474
$query = $this->db->GetQuery($sql);
475
476
if
($query->eof())
477
{
478
$idsessao = $this->db->GetNewId(
'seq_miolo_session'
,
'miolo_sequence'
);
479
$ts = $this->manager->GetSysTime();
480
$sql =
new
sql
(
'idsession,tsin,tsout,iduser,host,sid,sessiondata'
,
'miolo_session'
);
481
$this->db->Execute($sql->Insert(array($idsessao, $ts,
''
, $iduser, $this->host,
$id
, $data)));
482
}
483
else
484
{
485
$sql =
new
sql
(
'iduser,sessiondata'
,
'miolo_session'
,
'sid=?'
);
486
$this->db->Execute($sql->Update(array($iduser, $data,
$id
)));
487
}
488
489
return
TRUE;
490
}
491
501
function
delete
(
$id
)
502
{
503
$sql =
new
sql
(
'tsout'
,
'miolo_session'
,
'sid=?'
);
504
$this->db->Execute($sql->Update(array(date(
'Y/m/d H:i:s'
),
$id
)));
505
return
TRUE;
506
}
507
517
function
garbage
(
$lifetime
)
518
{
519
return
TRUE;
520
}
521
}
522
?>
EMioloException
Definição
mexception.class:4
ETimeOutException
Definição
mexception.class:144
MService
Definição
mservice.class:7
MSession
Definição
msession.class:7
MSession\$lifetime
$lifetime
Definição
msession.class:31
MSession\start
start($sid=NULL)
Definição
msession.class:93
MSession\$cookie_path
$cookie_path
Definição
msession.class:21
MSession\__construct
__construct($name='')
Definição
msession.class:78
MSession\$mode
$mode
Definição
msession.class:41
MSession\SetName
SetName($name='')
Definição
msession.class:203
MSession\GetId
GetId()
Definição
msession.class:245
MSession\open
open()
Definição
msession.class:418
MSession\put_headers
put_headers()
Definição
msession.class:391
MSession\$allowcache
$allowcache
Definição
msession.class:57
MSession\write
write($id, $data)
Definição
msession.class:469
MSession\$trans_id_enabled
$trans_id_enabled
Definição
msession.class:52
MSession\setValue
setValue($var_name, $value)
Definição
msession.class:351
MSession\unregister
unregister($var_names)
Definição
msession.class:299
MSession\SetId
SetId($sid='')
Definição
msession.class:228
MSession\destroy
destroy()
Definição
msession.class:159
MSession\$cookiename
$cookiename
Definição
msession.class:26
MSession\close
close()
Definição
msession.class:430
MSession\checkTimeout
checkTimeout()
Definição
msession.class:180
MSession\$name
$name
Definição
msession.class:16
MSession\isRegistered
isRegistered($var_name)
Definição
msession.class:284
MSession\$cookie_domain
$cookie_domain
Definição
msession.class:36
MSession\$fallback_mode
$fallback_mode
Definição
msession.class:46
MSession\freeze
freeze()
Definição
msession.class:379
MSession\garbage
garbage($lifetime)
Definição
msession.class:517
MSession\$id
$id
Definição
msession.class:11
MSession\getValue
getValue($var_name)
Definição
msession.class:321
MSession\read
read($id)
Definição
msession.class:445
sql
Definição
compatibility.class:18
classes
services
msession.class
Gerado por
1.10.0