33 lines
950 B
PHP
33 lines
950 B
PHP
<?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);
|
|
}
|
|
?>
|