-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
70 lines (57 loc) · 1.75 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
session_start();
/* include constants */
include_once ("settings.php");
function isUser() {
return isset($_SESSION['loginOK']) && $_SESSION['loginOK'];
}
function isSuperUser($username = null) {
if($username == null) {
if(isUser()) {
$username = $_SESSION['userName'];
} else {
return false;
}
}
/* 在還未實作使用者等級之前先一律通過 */
return true;
}
function user_account_check($username, $password, $haveLink = null){
/* create a link if there's no one */
if ($haveLink == null) {
$link = mysql_connect(MYSQL_LOCATION, MYSQL_USERNAME, MYSQL_PASSWORD) or die("您瀏覽的網頁因為「網頁伺服器無法與MySQL伺服器建立連線」原因無法正常運作,請稍候再試,如果仍無法正常運作請聯絡網站管理人員處理。");
mysql_set_charset("utf8", $link);
} else {
$link = $haveLink;
}
$username_escaped = mysql_real_escape_string($username);
$query = "SELECT passwd FROM users WHERE name='$username_escaped'";
mysql_select_db(MYSQL_DATABASE);
$result = mysql_query($query);
$ret = false;
if (mysql_num_rows($result) == 1 && $password_hashed = mysql_result($result, 0)){
if (crypt($password, SALT) == $password_hashed){
$ret = $username;
}
}
if ($haveLink == null) {
mysql_close($link);
}
return $ret;
}
function setFlash($message, $type = "warning") {
$_SESSION['flash'] = array(
"message" => $message,
"type" => $type
);
}
function hasFlash() {
return isset($_SESSION['flash']);
}
function getFlash($drop = true) {
$flashMessage = $_SESSION['flash'];
if ($drop) {
unset($_SESSION['flash']);
}
return $flashMessage;
}