Guest Book

This commit is contained in:
2024-05-10 13:26:42 +02:00
parent 5adfb13d83
commit 54e43f4318
5 changed files with 242 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
include_once "../../base/errors.php";
include_once "../../base/headers.php";
session_start();
$_SESSION["error"] = [];
if (!isset($_POST["title"])) {
array_push($_SESSION["error"], "Title was not among the data sent.");
}
if (!isset($_POST["name"])) {
array_push($_SESSION["error"], "Name was not among the data sent.");
}
if (!isset($_POST["comment"])) {
array_push($_SESSION["error"], "Comment was not among the data sent.");
}
$title = trim($_POST["title"]);
$name = trim($_POST["name"]);
$comment = substr(trim($_POST["comment"]), 0, 250);
$time = time();
if ($title === "") {
array_push($_SESSION["error"], "The title was empty.");
}
if ($name === "") {
array_push($_SESSION["error"], "The name was empty.");
}
if ($comment === "") {
array_push($_SESSION["error"], "The comment was empty.");
}
if (count($_SESSION["error"]) > 0) {
Headers::redirect(".");
return;
}
$string = file_get_contents("data.json") ?? "[]";
$json = json_decode($string);
array_push($json, ["time" => $time, "title" => $title, "name" => $name, "comment" => $comment]);
file_put_contents("data.json", json_encode($json));
Headers::redirect(".");