-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.php
58 lines (53 loc) · 1.16 KB
/
user.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
<?php
require_once(dirname(__FILE__) . '/user/user.php');
$user = new User();
if (isset($_GET['action'])) {
$action = $_GET['action'];
if ($action == "login")
login();
elseif ($action == "logout")
logout();
elseif ($action == "register")
register();
elseif ($action == "del")
del();
else
exit("非法访问!");
exit();
}
exit("非法访问!");
function login() {
global $user;
$result = $user->login($_POST['username'], $_POST['password']);
if ($result['code'] != 0) {
header("Location:login.html?status=error");
exit();
}
header("Location:info.html");
exit();
}
function logout() {
global $user;
$result = $user->logout();
echo '注销登录成功!点击此处 <a href="login.html">登录</a>';
}
function register() {
global $user;
$result = $user->is_login();
if ($result['code'] != 0) {
header("Location:login.html");
exit();
}
$result = $user->add($_POST['username'], $_POST['password']);
echo json_encode($result);
}
function del() {
global $user;
$result = $user->is_login();
if ($result['code'] != 0) {
header("Location:login.html");
exit();
}
$result = $user->del($_POST['username']);
echo json_encode($result);
}