= htmlspecialchars($entry['message']) ?>
— = htmlspecialchars($entry['name']) ?> | = date("Y-m-d H:i", strtotime($entry['timestamp'])) ?>[ 'Authorization: Bot ' . $token, 'Content-Type: application/json', ], CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode(['recipient_id' => $userId]), CURLOPT_RETURNTRANSFER => true, ]); $response = json_decode(curl_exec($ch), true); curl_close($ch); if (empty($response['id'])) { return false; } // Send message to DM channel $ch = curl_init('https://discord.com/api/v10/channels/' . $response['id'] . '/messages'); curl_setopt_array($ch, [ CURLOPT_HTTPHEADER => [ 'Authorization: Bot ' . $token, 'Content-Type: application/json', ], CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode([ 'embeds' => [[ 'title' => $title, 'description' => $message, 'color' => 0x00ffff, 'timestamp' => date('c'), ]] ]), CURLOPT_RETURNTRANSFER => true, ]); curl_exec($ch); curl_close($ch); return true; } $dataFile = __DIR__ . '/guestbook.json'; // Make sure the JSON file exists if (!file_exists($dataFile)) { file_put_contents($dataFile, json_encode([])); } // Read existing entries safely $data = []; $fileContents = file_get_contents($dataFile); if ($fileContents !== false) { $decoded = json_decode($fileContents, true); if (is_array($decoded)) { $data = $decoded; } } // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Honeypot spam field if (!empty($_POST['website'])) { header("Location: guestbook.php"); exit; } $name = trim($_POST['name']); $message = trim($_POST['message']); if ($name && $message) { $entry = [ "id" => time(), "name" => substr($name, 0, 50), "message" => substr($message, 0, 500), "timestamp" => date("c") ]; // Add new entry at the beginning array_unshift($data, $entry); // Save back to JSON file if (file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT)) === false) { echo "
Error: Could not save guestbook entry. Check file permissions.
"; } else { // Send Discord notification $dmMessage = "**From:** {$entry['name']}\n\n{$entry['message']}"; sendDiscordDM($config, '📝 New Guestbook Entry', $dmMessage); } // Redirect to avoid form resubmission header("Location: guestbook"); exit; } } // Entries to display $entries = $data; ?>= htmlspecialchars($entry['message']) ?>
— = htmlspecialchars($entry['name']) ?> | = date("Y-m-d H:i", strtotime($entry['timestamp'])) ?>