Guestbook files added

This commit is contained in:
Shannon Kay 2025-02-23 16:27:55 -08:00 committed by GitHub
commit 71546b1bb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 282 additions and 0 deletions

51
README.md Normal file
View file

@ -0,0 +1,51 @@
#A Guestbook
This is Shannon's edition of a PHP guestbook. It's a very light fork of the [original php guestbook by baccyflap](http://baccyflap.com/res/gbdl/).
Here is the [demo guestbook](https://guestbook.pixels.pink).
## Requirements
php support on your web host
## Installation and Setup
- Download the files
- Make a `guestbook` directory(or subdomain) wherever you want your guestbook to be.
- Put `data.txt`, `style.css`, and `index.php` in your `guestbook` directory.
- Give the `data.txt` file read and write permissions(CHMOD 666)
- It should work after that, and you can fill out the form to sign the guestbook.
- I've left my first post in the guestbook `data.txt` so that you can see how the guestbook entries will look and not start with an empty guestbook, but you can delete it from the text file if you want.
- Optionally, you can edit `style.css` to style the page however you want. I used color variables, listed at the top of `style.css` to make it really simple to just change your color scheme if you like.
- You can edit `index.php` to change things like the `<title>` and the page header.
- I've included some comments in the code to help you find the welcome message to more easily edit that if you want.
- You'll find the footer down at the bottom, again with a comment to help you find where you might want to add a footer, like a link back to your website.
From the original ReadMe, included in full below.
> Somewhere in the PHP code, you'll also find some commented out lines (lines preceded by //); if you uncomment those and input your email address, you'll receive an email for each new message.
## Shannon Edition
I've very lightly forked this from the [original php guestbook by baccyflap](http://baccyflap.com/res/gbdl/).
The original is a beautifully simple guestbook which uses only two files and works with very little setup.
The changes I made were mostly structure and style of the index page html, making it more mobile friendly, and making the stylesheet external for easier style changes. Now it's three files instead of two, but I think it's easier to style with the external stylesheet. I even put in color variables to make it extra simple to pick your own color scheme.
I also added some comments on the index page to help people find where to edit some text on the page they might want to edit.
2025-02-23
Shannon Kay
https://web.pixelshannon.com/aguestbook/
***
## Original Readme
I wrote this guestbook in PHP, as simple as I could make it. It's almost ready to use straight out of the box; all you need to do to get it working is to place all files in the same directory and ensure that data.txt has the appropriate permissions: CHMOD 666.
The guestbook data is written directly to a textfile, data.txt, from which it also reads data to reproduce on the same page. There's a cheeky little PHP redirect involved that makes it so that refreshing the page doesn't repost the message. There's also an even cheekier little field in the form that appears 1000 pixels left of your viewport. You don't see it, but bots do, and if they put a value in that field, nothing is posted - it's primitive spam control.
Somewhere in the PHP code, you'll also find some commented out lines (lines preceded by //); if you uncomment those and input your email address, you'll receive an email for each new message. Neat stuff.
Thanks to Gus for catching bugs and instructing me on how to clean up and improve some of the code.
I hereby publish this guestbook into the public domain. If you want to use and adapt it, go forth and be merry, no credits required - although a link is always appreciated.
2024-05-16
rmf
baccyflap.com

1
data.txt Normal file
View file

@ -0,0 +1 @@
<a href="http://www.shannonkay.com" target="_blank">Shannon</a>,1739570732,First Guest 🦄.

119
index.php Normal file
View file

@ -0,0 +1,119 @@
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Guestbook</title>
<meta name="theme-color" content="#f9dee1">
<link rel="stylesheet" href="style.css">
<?php
$data = 'data.txt';
$contents = file_exists($data) ? file_get_contents($data) : '';
if (!empty($contents)) {
$lines = explode("\n", $contents);
$posts = array();
foreach ($lines as $line) {
$parts = explode(',', $line);
if (count($parts) > 1) {
$posts[] = array('user' => $parts[0],
'time' => date('Y-m-d', $parts[1]),
'message' => $parts[2]);
}
}
}
$error = false;
if (isset($_POST['userpost']) && empty($_POST['email'])) {
$name = trim($_POST['userpost']);
$name = str_replace(',', '&#44;', $name);
$name = filter_var($_POST['userpost'], FILTER_SANITIZE_STRING);
$url = filter_var($_POST['urlpost'], FILTER_SANITIZE_STRING);
$url = trim($url);
$url = str_replace('http://','',$url);
$url = str_replace('https://','',$url);
$url = rtrim($url,"/");
$time = time();
$message = filter_var($_POST['messagepost'], FILTER_SANITIZE_STRING);
$message = str_replace("\r\n", "<br>", $message);
$message = str_replace(',', '&#44;', $message);
if (($name != '') AND ($message != '')
) {
if (!empty($url)) {
$user = '<a href="http://' . $url . '" target="_blank">' . $name . '</a>';
} else {
$user = $name;
}
$line = $user . ',' . $time . ',' . $message . "\n";
// uncomment the two lines below and add your email address if you want to receive an email when you get a new message
// $mailline = "a message by " . $name . " @ " . date('Y-m-d H:i', $time) . "\n" . $url . "\n\n" . $_POST['messagepost'];
// mail('your@email.com', 'guestbook entry', $mailline);
header('Location:./');
$file = fopen($data, 'a');
if (!fwrite($file, $line)) {
$error = '<div class="mssg">I could not post your message, probably a problem with serverside file permissions.</div>';
}
fclose($file);
unset($_POST);
} else {
$error = '<div class="mssg">It looks to me like you did not fill in a name or a message.</div>';
}
}
?>
</head>
<body>
<h1>Guestbook</h1>
<p id="welcome">
<!-- Welcome message -->
Welcome to my guestbook.
</p>
<p id="rules">Please use only plain text when writing your message; your <code>&lt;html&gt;</code> has no power in this place.</p>
<section id="form">
<form action="./#message" method="post" id="t">
<label id="message">Message<br>
<textarea name="messagepost" maxlength="3000"><? if (isset($_POST['userpost'])) echo $_POST['messagepost']; ?></textarea></label>
<p><label for="name">Name<br>
<input type="text" name="userpost" maxlength="100" size="25"<? if (isset($_POST['userpost'])) echo 'value="' . $_POST['userpost'] . '"'; ?>></label></p>
<p>
<label>Website <span class="small">(optional)</span><br>
<input type="text" maxlength="100" name="urlpost" size="25"<? if (isset($_POST['userpost'])) echo 'value="' . $_POST['urlpost'] . '"'; ?>><br>
<span class="small">(<em>not</em> your email address)<br>
If you don't have a website, consider including a link to your Mastodon or Bluesky profile.</span></label><p>
<input type="submit" name="submit" value="Sign the Guestbook" class="button">
<label style="position:absolute; left:-5000px">don't put anything in this field!<br><input type="text" name="email" style="position:absolute; left:-5000px" size="16"<? if (isset($_POST['email'])) echo 'value="' . $_POST['email'] . '"'; ?>></label>
</form>
</section>
<h2>Guests</h2>
<? if ($error !== false): echo $error;
endif;
if (!empty($contents)) {foreach (array_reverse($posts) as $post): echo
'<div class="mssg"><div class="info">Signed by <span class="user">',$post['user'],
'</span><span class="date"> (',$post['time'],')</span></div>',
stripslashes($post['message']),'</div>', "\n";
endforeach;} else {echo '<div class="mssg">I could not post your message, probably a problem with serverside file permissions.</div>';}
?>
<footer>
<p>
<!-- Put a footer here if you want it. -->
</p>
<p><a href="https://web.pixelshannon.com/aguestbook/">Have A Guestbook</a></p>
</footer>
</body>
</html>

111
style.css Normal file
View file

@ -0,0 +1,111 @@
:root {
--background-color: #f9dee1;
--text-color: #000000;
--header-color: #f87dac;
--form-border: #a48ac9;
--button-color: #f87dac;
--button-border: #a48ac9;
--button-text: #ffffff;
--message-background: #ffffff;
--message-border: #f87dac;
--info-background: #fbeaec;
--link-color: #8c5ca5;
--link-hover-color: #f76ca2;
--guest-name: #a48ac9;
--footer-border: #a48ac9;
}
body {
background-color: var(--background-color);
text-align: center;
font-family: Verdana, sans-serif;
font-size: 1.25rem;
line-height: 1.5;
min-height: 100vh;
color: var(--text-color);
}
#rules {
font-size: 1rem;
}
textarea {
border-color: var(--form-border);
border-style: solid;
border-width: 0.15rem;
padding: 0.5rem;
font-size: 1rem;
width: 350px;
max-width: 400px;
height: 150px;
}
input {
border-color: var(--form-border);
border-style: solid;
border-width: 0.15rem;
padding: 0.5rem;
font-size: 1rem;
}
.button {
background-color: var(--button-color);
border: 0.2rem solid var(--button-border);
font-weight: bold;
color: var(--button-text);
}
.info {
font-weight: normal;
text-align: justify;
background-color: var(--info-background);
padding: 0.2rem;
font-size: 1rem;
}
.small {
font-size: 1rem;
}
.mssg {
margin: 0.5rem;
padding: 1rem;
padding-top: 0.5rem;
background-color: var(--message-background);
border-color: var(--message-border);
border-style: solid;
border-width: 0.2rem;
}
.user {
font-weight: bold;
font-size: 1.2rem;
color: var( --guest-name);
}
.date {
font-size: 1rem;
}
h1 {
text-align: center;
font-size: 2.75rem;
color: var(--header-color);
margin-top: 1pt;
margin-bottom: 5pt;
}
h2 {
text-align: left;
font-size: 2rem;
color: var(--header-color);
margin-top: 1pt;
margin-bottom: 0.2rem;
margin-left: 1rem;
}
a, a:visited {
color: var(--link-color);
}
a:hover, a:active {
font-weight: bold;
color: var(--link-hover-color);
}
code {
font-family: Menlo, Monaco, 'Courier New', monospace;
}
footer {
font-size: 1rem;
border-top: 0.2rem solid var(--footer-border);
text-align: center;
padding: 1rem;
margin-top: 0;
}