<?php
session_start();
if (!isset($_SESSION['admin'])) {
  die('Unauthorized access.');
}

$id = (int)($_POST['id'] ?? -1);

$file = '../comments.txt';
if (!file_exists($file)) {
  die('Comments file not found.');
}

$entries = explode("---\n", file_get_contents($file));
if (!isset($entries[$id])) {
  die('Comment not found.');
}

unset($entries[$id]);
file_put_contents($file, implode("---\n", $entries));

header('Location: dashboard.php');
