Finish Production- Release

This commit is contained in:
Evan G. 2024-04-26 16:32:37 -05:00
parent 3ac5490498
commit 3034b501eb
Signed by: fbievan
GPG Key ID: 55FAB8CB6842F080
3 changed files with 58 additions and 12 deletions

View File

@ -9,3 +9,7 @@
padding-bottom: 20px;
padding-top: 10px;
}
.date {
padding-top: 0px;
padding-bottom: 15px;
}

View File

@ -29,6 +29,9 @@
echo "<h4>";
echo $post["name"] . "<br>";
echo "</h4>";
echo '<h4 class="date">';
echo $post["date"] . "<br>";
echo "</h4>";
echo "<p>";
echo $post["message"] . "<br>";
echo "</p>";

View File

@ -1,35 +1,74 @@
<?php
# Define Inital Variables
$fname = htmlspecialchars($_POST["fname"]);
$fmsg = htmlspecialchars($_POST["fmessage"]);
$savemsg = array("name" => $fname, "message" => $fmsg);
class data {
public $name;
public $message;
public $date;
public $mlength;
public $nlength;
function set_date() {
$this->date = date("Y M d");
}
function set_mlength() {
$this->mlength = strlen($this->message);
}
function set_nlength() {
$this->nlength = strlen($this->name);
}
}
$ndata = new data();
$name = $ndata->name = htmlspecialchars($_POST["fname"]);
$message = $ndata->message = htmlspecialchars($_POST["fmessage"]);
$ndata->set_date();
$ndata->set_mlength();
$ndata->set_nlength();
$mlength = $ndata->mlength;
$nlength = $ndata->nlength;
# Setup JSON
$data = json_decode(file_get_contents('test.json'), true);
# Add
array_unshift($data , $savemsg);
$newURL = "http://192.168.1.180:9890/guestbook/index.html";
# Check name and message
if ($fname == "") {
# Check name and message
if ($name == "") {
header('Refresh:2; url=' . $newURL );
echo "There is no name, Try again with a name";
exit();
}
if ($fmsg == "") {
if ($message == "") {
header('Refresh:2; url=' . $newURL );
echo "There is no message, Try again with a message";
exit();
}
if($mlength > 200) {
header('Refresh:2; url=' . $newURL );
echo "This message is too long";
exit();
}
if($nlength > 12) {
header('Refresh:2; url=' . $newURL );
echo "The name is too long";
exit();
}
$data = json_decode(file_get_contents('test.json'), true);
foreach($data as $post) {
if ($post["message"] == $message) {
echo "Another message with this text already exists";
header('Refresh:2; url=' . $newURL );
exit();
}
}
array_unshift($data , $ndata);
file_put_contents('test.json', json_encode($data, JSON_PRETTY_PRINT));
header('Refresh:2; url=' . $newURL );