diff --git a/api.php b/api.php index f1bd0a4..30c5844 100644 --- a/api.php +++ b/api.php @@ -4,7 +4,6 @@ header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS"); header("Access-Control-Allow-Headers: Content-Type, Authorization"); -// NOUVEAU : Interdire formellement au navigateur de mettre en cache les requêtes API header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Pragma: no-cache"); @@ -16,6 +15,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { define('ENCRYPTION_KEY', 'MaCleSecreteSuperRobuste123!'); try { + // Vérifiez bien que "root" et "" correspondent aux identifiants de votre base de données locale $pdo = new PDO("mysql:host=localhost;dbname=mon_cinema;charset=utf8mb4", "root", "", [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC @@ -67,7 +67,6 @@ function checkAuth($pdo) { $stmtCheck = $pdo->query("SELECT COUNT(*) FROM users"); if ($stmtCheck->fetchColumn() == 0) return true; - // NOUVEAU : Récupération du token sécurisée contre les serveurs Apache récalcitrants $token = $_SERVER['HTTP_AUTHORIZATION'] ?? ''; if (empty($token) && function_exists('apache_request_headers')) { $headers = apache_request_headers(); @@ -151,29 +150,23 @@ switch ($action) { } echo json_encode(["success" => true]); break; + + case 'delete_film': + checkAuth($pdo); + $type = $_GET['type'] ?? 'critique'; + $table = ($type === 'videotheque') ? 'videotheque' : 'critiques'; + $id = $_GET['id'] ?? null; -case 'delete_film': - checkAuth($pdo); - $type = $_GET['type'] ?? 'critique'; - $table = ($type === 'videotheque') ? 'videotheque' : 'critiques'; - $id = $_GET['id'] ?? null; - - if (!$id) { - http_response_code(400); - echo json_encode(["error" => "ID manquant."]); - break; - } - - $stmt = $pdo->prepare("DELETE FROM $table WHERE id = ?"); - $stmt->execute([$id]); - - if ($stmt->rowCount() === 0) { - http_response_code(404); - echo json_encode(["error" => "Aucun enregistrement trouvé avec cet ID."]); - } else { + if (!$id) { + http_response_code(400); + echo json_encode(["error" => "ID manquant."]); + break; + } + + $stmt = $pdo->prepare("DELETE FROM $table WHERE id = ?"); + $stmt->execute([$id]); echo json_encode(["success" => true]); - } - break; + break; case 'bulk_delete': checkAuth($pdo);