Add http_response_code to "apiresult" function

This commit is contained in:
Bofh 2022-11-22 11:55:58 +01:00
parent a8128d1a00
commit 741e9994d4
2 changed files with 4 additions and 5 deletions

View File

@ -3,10 +3,8 @@
<?php
$uri = trim($_GET['uri']);
if (!preg_match('/^\d+\.\d+\.\d+\.\d+:\d+$/', $uri)) {
http_response_code(400);
apiresult(['error' => 'The given URI must match IPV4_HOST:PORT scheme']);
}
if (!preg_match('/^\d+\.\d+\.\d+\.\d+:\d+$/', $uri))
apiresult(['error' => 'The given URI must match IPV4_HOST:PORT scheme'], 400);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://$uri");

View File

@ -23,7 +23,8 @@ $supported_ap_software = [
];
// functions
function apiresult($data) {
function apiresult($data, $code=200) {
if ($code !== 200) http_response_code($code);
header('Content-Type: application/json');
echo json_encode($data); die;
}