First Commit
This commit is contained in:
commit
3c7bd7aa90
|
@ -0,0 +1 @@
|
|||
A Really cool guestbook made by fbievan! See https://fbievan.live/posts/phpguestbook/ for my thought process while making this
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>My Cool Guestbook!</title>
|
||||
<link rel="stylesheet" href="../readable.css"</link>
|
||||
<link rel="stylesheet" href="./guestbook.css"</link>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Guestbook</h1>
|
||||
<p>This is a guestbook, made by fbievan</p>
|
||||
</header>
|
||||
<nav>
|
||||
<a href="../index.html">Back Home</a>
|
||||
</nav>
|
||||
<main>
|
||||
<form action="./submit.php" method="post">
|
||||
<input type="text" name="fname" placeholder="name"></input>
|
||||
<input type="text" name="fmessage" placeholder="Message"></input>
|
||||
<input type="submit"></input>
|
||||
</form>
|
||||
<?php
|
||||
$data = json_decode(file_get_contents('test.json'), true);
|
||||
echo "<div>";
|
||||
foreach($data as $post) {
|
||||
echo '<section class="guestbookpost">';
|
||||
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>";
|
||||
echo "</section>";
|
||||
}
|
||||
echo "</div>";
|
||||
|
||||
?>
|
||||
</main>
|
||||
<footer>
|
||||
I'm cool
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
|
||||
<channel>
|
||||
<title>Fbi's Epic Guestbook RSS Feed</title>
|
||||
<link>https://www.w3schools.com</link>
|
||||
<description>A cool Guestbook made by fbievan</description>
|
||||
<?php
|
||||
$data = json_decode(file_get_contents('test.json'), true);
|
||||
?>
|
||||
<?php foreach($data as $post): ?>
|
||||
<item>
|
||||
<title><?php echo $post["name"];?></title>
|
||||
<description><?php echo htmlspecialchars($post["message"]);?></description>
|
||||
</item>
|
||||
<?php endforeach; ?>
|
||||
</channel>
|
||||
</rss>
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
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
|
||||
|
||||
$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();
|
Loading…
Reference in New Issue