From 3c7bd7aa909519d9b927a8053b135b5305a91de1 Mon Sep 17 00:00:00 2001 From: "Evan G." Date: Sat, 18 May 2024 17:51:55 -0500 Subject: [PATCH] First Commit --- README.md | 1 + guestbook.css | 21 ++++++++++++++ index.html | 48 ++++++++++++++++++++++++++++++++ index.xml | 18 ++++++++++++ submit.php | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 README.md create mode 100644 guestbook.css create mode 100644 index.html create mode 100644 index.xml create mode 100644 submit.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..a253fa1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +A Really cool guestbook made by fbievan! See https://fbievan.live/posts/phpguestbook/ for my thought process while making this diff --git a/guestbook.css b/guestbook.css new file mode 100644 index 0000000..1562ea5 --- /dev/null +++ b/guestbook.css @@ -0,0 +1,21 @@ +.guestbookpost { + padding: 10px; + border: var(--line-width) solid; + border-left-style: none; + border-right-style: none; + border-top-style: solid; + border-bottom-style: none; + text-align: left; + padding-bottom: 20px; + padding-top: 10px; + } +.date { + padding-top: 0px; + padding-bottom: 15px; +} +h4 { + margin-top: 0px; +} +p { + padding-left: 4px; +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..940b381 --- /dev/null +++ b/index.html @@ -0,0 +1,48 @@ + + + + + My Cool Guestbook! + + + + + +
+

Guestbook

+

This is a guestbook, made by fbievan

+
+ +
+
+ + + +
+ "; + foreach($data as $post) { + echo '
'; + echo "

"; + echo $post["name"] . "
"; + echo "

"; + echo '

'; + echo $post["date"] . "
"; + echo "

"; + echo "

"; + echo $post["message"] . "
"; + echo "

"; + echo "
"; + } + echo ""; + + ?> +
+ + + diff --git a/index.xml b/index.xml new file mode 100644 index 0000000..9c671f7 --- /dev/null +++ b/index.xml @@ -0,0 +1,18 @@ + + + + + Fbi's Epic Guestbook RSS Feed + https://www.w3schools.com + A cool Guestbook made by fbievan + + + + <?php echo $post["name"];?> + + + + + diff --git a/submit.php b/submit.php new file mode 100644 index 0000000..b02516d --- /dev/null +++ b/submit.php @@ -0,0 +1,76 @@ +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 + +$newURL = "https://" . $_SERVER['SERVER_NAME'] . "/guestbook/index.html"; + +# Check name and message +if ($name == "") { + header('Refresh:2; url=' . $newURL ); + echo "There is no name, Try again with a name"; + exit(); +} +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 > 25 ) { + 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 ); +echo "Your submisson has been added"; +exit();