1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
if (!isset($S)) {
$S=array();
}
$S=array_merge($S, array(
'request' => $_GET['req'],
'notemplates' => false,
'title' => null,
'scripts' => array(),
'head' => null,
'head_css' => array(),
'head_scripts' => array(),
'debug' => null,
'debugrow' => 0,
'cookie_dir' => null,
'start' => microtime(true),
'sql' => null
));
unset($_REQUEST['req'], $_GET['req']);
$S['cookie_dir']=substr($conf['url'], strpos($conf['url'], '/', 8)).'/';
require_once(SHARED.'/include/dbinit.php');
if (isset($_COOKIE[$conf['cookiename']])) {
$cookie=$_COOKIE[$conf['cookiename']];
debug('session', 'cookie received '.$conf['cookiename'].'='.htmlentities($cookie));
if (preg_match('/[a-z0-9]{30}/', $cookie)) {
$r=$S['pdo']->query('SELECT * FROM `sessions` WHERE `id`="'.$cookie.'"');
if ($r->rowCount()) {
$S['session']=new sql_session($r->fetch(PDO::FETCH_ASSOC));
if ($S['session']->atime+$S['session']->expire < time()) {
setcookie($conf['cookiename'], '', 1, $S['cookie_dir'], '', false, true);
$S['sesion']->delete();
unset($S['session']);
} else {
$S['session']->atime=time();
$S['session']->write();
$S['user']=new sql_user($S['session']->user);
debug('session', 'sessionid='.$S['session']->id.', email='.$S['user']->email);
setcookie($conf['cookiename'], $S['session']->id, time()+$conf['sessionlength'], $S['cookie_dir'], '', false, true);
}
} else {
debug('session', 'session not found');
setcookie($conf['cookiename'], '', 1, $S['cookie_dir'], '', false, true);
}
} else {
debug('session', 'session id invalid');
}
}
?>
|