-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
48 lines (41 loc) · 1.01 KB
/
functions.php
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
function getDBObject($uri) {
$tmp = explode(':', $uri);
$proto = Trim($tmp[0]);
$pdata = Trim($tmp[1]);
if ($proto == 'file')
return new DatabaseFile( $pdata );
else
if ($proto == 'mysql')
return new DatabaseMySQL( $pdata );
return false;
}
function verify_user($db, $perm=false) {
if (array_key_exists('logged_in', $_SESSION)) {
if ($perm != false) {
if ($_SESSION['user_perms'] == '*')
return true;
else
return ($_SESSION['user_perms'] & $perm) ? true : false;
}
else
return true;
}
$logged_in = false;
if (array_key_exists('user', $_POST)) {
$perm = $db->verify_user($_POST['user'], $_POST['password']);
if (is_string($perm)) {
$logged_in = base64_encode("{$_POST['user']}\n{$_POST['password']}");
if ($perm == true) {
$_SESSION['user_perms'] = '*';
$_SESSION['logged_in'] = $logged_in;
}
else {
$_SESSION['user_perms'] = $perm;
$_SESSION['logged_in'] = $logged_in;
}
}
}
return $logged_in;
}
?>