FabrikaHradekTour/res/forum/api/list_users.php

29 lines
605 B
PHP
Raw Normal View History

2024-05-20 19:15:35 +02:00
<?php
2024-05-20 20:07:28 +02:00
include("../../global.php");
2024-05-20 20:03:59 +02:00
session_start();
if (!isset($_SESSION["username"])) goto fail;
$out = $database -> query("SELECT username, admin FROM user WHERE username=\"" . $_SESSION["username"] . "\" AND admin=\"1\"");
if ($out -> num_rows != 1)
{
fail:
echo "nope";
2024-05-20 20:07:28 +02:00
header("Location: ../../../index.php");
2024-05-20 20:03:59 +02:00
return;
}
2024-05-20 19:15:35 +02:00
2024-05-20 19:34:29 +02:00
$out = $database -> query("SELECT username FROM user ORDER BY id ASC");
2024-05-20 19:15:35 +02:00
2024-05-21 20:02:52 +02:00
$output = array();
2024-05-20 19:15:35 +02:00
while ($res = $out -> fetch_assoc())
{
2024-05-21 20:02:52 +02:00
array_push($output, $res["username"]);
}
header('Content-type: application/json');
echo json_encode(["users" => $output]);