xref: /web-master/fetch/allusers.php (revision 0e511803)
1<?php // vim: et ts=4 sw=4
2function error($text, $status)
3{
4    switch((int)$status) {
5    default:
6    case 500:
7        header("HTTP/1.0 500 Internal server error");
8        break;
9
10    case 404:
11        header("HTTP/1.0 404 Not Found");
12        break;
13
14    case 401:
15        header("HTTP/1.0 401 Unauthorized");
16        break;
17    }
18    echo json_encode(["error" => $text]);
19    exit;
20}
21
22(!isset($_GET['token']) || md5($_GET['token']) != "d3fbcabfcf3648095037175fdeef322f") && error("token not correct.", 401);
23
24$pdo = new PDO("mysql:host=localhost;dbname=phpmasterdb", "nobody", "");
25
26$stmt = $pdo->prepare("SELECT name, username FROM users WHERE enable AND cvsaccess");
27if (!$stmt->execute()) {
28    error("This error should never happen", 500);
29}
30
31$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
32if (!$results) {
33    error("This should never happen either", 404);
34}
35
36echo json_encode($results);
37
38
39