3v4l.org

run code in 300+ PHP versions simultaneously
<?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.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12, 8.1rc1 - rc3
{"message":"Missing\/Invalid identifier provided"}

preferences:
64.66 ms | 541 KiB | 20 Q