08-12-周三_16-44-56
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// 接受数据,并且提取出action
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$action = $data['action'] ?? '';
|
||||
|
||||
include 'db.php';
|
||||
|
||||
// 如果数据库连接失败,则返回错误信息
|
||||
/** @var mysqli $conn */
|
||||
if (!isset($conn)) {
|
||||
echo json_encode(['code' => 10004, 'status' => 'error', 'message' => '数据库连接失败']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 判断是否admin登录
|
||||
session_start();
|
||||
if (!isset($_SESSION['username'])) {
|
||||
echo "<script>alert('请登录');setTimeout(function(){location.href='login.html';},1000);</script>";
|
||||
exit;
|
||||
}
|
||||
if ($_SESSION['username'] != 'admin') {
|
||||
echo "<script>alert('请登录管理员账号');setTimeout(function(){location.href='login.html';},1000);</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取所有的用户信息
|
||||
if($action=='getUsers'){
|
||||
$sql = "select * from users";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
$users = mysqli_fetch_all($result, MYSQLI_ASSOC);
|
||||
echo json_encode($users);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user