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-bottom: 20px;
padding-top: 10px; padding-top: 10px;
} }
.date {
padding-top: 0px;
padding-bottom: 15px;
}

View File

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

View File

@ -1,35 +1,74 @@
<?php <?php
class data {
# Define Inital Variables public $name;
$fname = htmlspecialchars($_POST["fname"]); public $message;
$fmsg = htmlspecialchars($_POST["fmessage"]); public $date;
$savemsg = array("name" => $fname, "message" => $fmsg); 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 # 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"; $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 ); header('Refresh:2; url=' . $newURL );
echo "There is no name, Try again with a name"; echo "There is no name, Try again with a name";
exit(); exit();
} }
if ($fmsg == "") { if ($message == "") {
header('Refresh:2; url=' . $newURL ); header('Refresh:2; url=' . $newURL );
echo "There is no message, Try again with a message"; echo "There is no message, Try again with a message";
exit(); 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)); file_put_contents('test.json', json_encode($data, JSON_PRETTY_PRINT));
header('Refresh:2; url=' . $newURL ); header('Refresh:2; url=' . $newURL );