<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Credentials: true");
header("Content-Type: application/json; charset=UTF-8");
function getResponse() {
if (!isset($_GET['id']) || !ctype_digit($_GET['id'])) {
return ['message' => 'Missing/Invalid identifier provided'];
}
include_once('config_setup.php');
$sql = "SELECT id, caption, filename, description2 FROM photographs WHERE id = " . $_GET['id'];
$result = mysqli_query($db, $sql);
if (!$result) {
return ['message' => 'Please contact the dev team.'];
}
$photo = mysqli_fetch_assoc($result);
if (!$photo) {
return ['message' => 'No product.'];
}
$url = 'http://localhost/photo_gallery/public/files/images/';
$allowed = '<div><img><h1><h2><p><br><strong><em><ul><li><table><td><tr><th><tbody>';
return [
'id' => urlencode(htmlspecialchars($photo['id'])),
'caption' => htmlspecialchars($photo['caption']),
'filename' => $url . htmlspecialchars($photo['filename']),
'description2' => strip_tags($photo['description2'], $allowed),
];
}
$response = getResponse();
http_response_code(isset($response['message']) ? 404 : 200);
echo json_encode($response);
- Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- {"message":"Missing\/Invalid identifier provided"}
preferences:
154.25 ms | 407 KiB | 5 Q