FabrikaHradekTour/res/forum/api/list_users.php

29 lines
612 B
PHP

<?php
include("../../global.php");
session_start();
if (!isset($_SESSION["username"])) goto fail;
$out = $database -> query("SELECT username, admin FROM user WHERE BINARY username=\"" . $_SESSION["username"] . "\" AND admin=\"1\"");
if ($out -> num_rows != 1)
{
fail:
echo "nope";
header("Location: ../../../index.php");
return;
}
$out = $database -> query("SELECT username FROM user ORDER BY id ASC");
$output = array();
while ($res = $out -> fetch_assoc())
{
array_push($output, $res["username"]);
}
header('Content-type: application/json');
echo json_encode(["users" => $output]);