summaryrefslogtreecommitdiff
blob: 825d759b2d629bd27f6cab97cfa91a50aa5b4e35 (plain)
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
49
<?php
if (!isset($S)) {
	$S=array();
}
$S=array_merge($S, array(
	'death' => '',
	'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($S['conf']['url'], strpos($S['conf']['url'], '/', 8)).'/';
require_once(SHARED.'/include/dbinit.php');
if (isset($_COOKIE[$S['conf']['cookiename']])) {
	$cookie=$_COOKIE[$S['conf']['cookiename']];
	debug('session', 'cookie received '.$S['conf']['cookiename'].'='.htmlentities($cookie));
	if (preg_match('/[a-z0-9]{30}/', $cookie)) {
		$r=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($S['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($S['conf']['cookiename'], $S['session']->id, time()+$S['conf']['sessionlength'], $S['cookie_dir'], '', false, true);
			}
		} else {
			debug('session', 'session not found');
			setcookie($S['conf']['cookiename'], '', 1, $S['cookie_dir'], '', false, true);			
		}
	} else {
		debug('session', 'session id invalid');
	}
}
?>