-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.php
More file actions
25 lines (18 loc) · 691 Bytes
/
json.php
File metadata and controls
25 lines (18 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
UMLPoll\Database::connect($DB_SERVER, $DB_USER, $DB_PASS, $DB_DATABASE);
UMLPoll\Database::charset("utf8");
$json_data = UMLPoll\Poll\Poll::get(filter_input(INPUT_GET, 'id'));
UMLPoll\Database::close();
$json = json_encode(($json_data === NULL ? ["error" => 404] : $json_data), JSON_PRETTY_PRINT);
if ($json === false) {
$json = json_encode(array("jsonError", json_last_error_msg()));
if ($json === false) {
$json = '{"jsonError": "unknown"}';
}
http_response_code(500);
}
echo $json;