aboutsummaryrefslogtreecommitdiff
path: root/src/Pages/guestbook/guestbook.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Pages/guestbook/guestbook.php')
-rw-r--r--src/Pages/guestbook/guestbook.php102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/Pages/guestbook/guestbook.php b/src/Pages/guestbook/guestbook.php
new file mode 100644
index 0000000..3e70b83
--- /dev/null
+++ b/src/Pages/guestbook/guestbook.php
@@ -0,0 +1,102 @@
+<?php
+// Enable error reporting while debugging
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+$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 "<p style='color:red'>Error: Could not save guestbook entry. Check file permissions.</p>";
+ }
+
+ // Redirect to avoid form resubmission
+ header("Location: guestbook");
+ exit;
+ }
+}
+
+// Entries to display
+$entries = $data;
+?>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Guestbook</title>
+<link rel="stylesheet" href="../style.css">
+</head>
+<body>
+
+<canvas id="bg"></canvas>
+<div class="container">
+<h1>256phi Guestbook</h1>
+
+<form method="POST">
+ <input type="text" name="name" placeholder="Your name" required>
+ <textarea name="message" placeholder="Leave a message..." required></textarea>
+
+ <!-- Honeypot -->
+ <input type="text" name="website" style="display:none">
+
+ <button type="submit">Sign</button>
+</form>
+
+<hr>
+
+<?php foreach ($entries as $entry): ?>
+ <div class="entry">
+ <p><?= htmlspecialchars($entry['message']) ?></p>
+ <small>
+ — <?= htmlspecialchars($entry['name']) ?>
+ | <?= date("Y-m-d H:i", strtotime($entry['timestamp'])) ?>
+ </small>
+ </div>
+<?php endforeach; ?>
+
+<footer>
+ <p>© 256phi | 2026 | <a href="/home">Home</a></p
+</footer>
+</div>
+<script type="module" src="../main.js"></script>
+</body>
+</html>