aboutsummaryrefslogtreecommitdiff
path: root/guestbook/guestbook.php
diff options
context:
space:
mode:
authorNatasha Moongrave <natasha@256phi.eu>2026-03-22 22:49:43 +0100
committerNatasha Moongrave <natasha@256phi.eu>2026-03-22 22:49:43 +0100
commiteafcf42df95baa2e2faa6525183f13769e8bfd76 (patch)
treee48ce5071af6e49e3db58457cd1944b57f564504 /guestbook/guestbook.php
parent5bad12334d9032005b3468b3f523688964c31d50 (diff)
Moved the guestbook and its code from ./guestbook to src/Pages/guestbook
Diffstat (limited to 'guestbook/guestbook.php')
-rw-r--r--guestbook/guestbook.php102
1 files changed, 0 insertions, 102 deletions
diff --git a/guestbook/guestbook.php b/guestbook/guestbook.php
deleted file mode 100644
index 3e70b83..0000000
--- a/guestbook/guestbook.php
+++ /dev/null
@@ -1,102 +0,0 @@
-<?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>