3.9 KiB
guestbook.php
This is a guestbook system for personal websites! Its gimick is that it's simple enough to fit in one file (the SQLite database is technically another file, but guestbook.php
will generate and handle it all on its own).
Setup
Assuming you have PHP installed on your server, setting up this guestbook should be as easy as dropping guestbook.php
into a folder. It will create the database and necessary tables on the first load. If it doesn't work immediately it's probably a bug and I'd encourage you to reach out to me about it.
Have the latest version of PHP installed, and make sure you have SQLite3 set up as well. On Debian, if you don't have php-8.2-sqlite3
installed, you can install it by running:
$ sudo apt install php8.2-sqlite3
I've tested this using PHP 8.2. It seems like the Debian package php8.3-sqlite3
is still experimental as of writing (2024-03-10) so some additional setup may be required to get it working with PHP 8.3 if you're on Debian.
If you just want to test it out without installing something like Nginx, you can use some built in PHP utilities to run a simple server. Run this in the directory where you downloaded guestbook.php
php -S localhost:8080
Then, navigate to http://localhost:8080/guestbook.php
in your browser.
Configuring
Several constants are defined at the very top of guestbook.php
using the PHP define
function, which works as follows:
define('[name of constant]', [PHP expression]);
You can change these constants according to your need. You can also search the file for references to them to see where they're used:
GUESTBOOK_NAME
- The name of your guestbook! Used as the page titleGUESTBOOK_PAGE_SIZE
- The maximum number of guestbook entries to display on a single page. Additional entries will be moved to the next page, reachable by clicking the navigation buttons at the bottom of the documentGUESTBOOK_RATE_LIMIT_SECONDS
- The number of seconds between allowable submissions to the guestbook (i.e. for a rate limit of N seconds, users can only publish an entry every N seconds). Used as a spam prevention mechanism.GUESTBOOK_SQLITE_LOCATION
- The location of the database. If the database isn't found at the location, a new one will be created. Make sure your server has the ability to write to this location!CHALLENGE_QUESTION
- An additional question added to the form as a spam prevention mechanism. The default is "What month is it?" which will trip up LLM-enabled spam bots 11 out of 12 times. If a user doesn't answer correctly, their submission will be quietly ignoredCHALLENGE_ANSWER_REGEX
- A regex matching all correct answers to the challenge questionSHADOWBAN_REGEX
- If any of the fields (except the challenge question) match this regex, they will be quietly ignored. You may want to use this to block certain keywords you don't want showing up in your guestbook.
Beneath the PHP script at the top of the file, there's the complete HTML page for the guestbook, including the style sheet in the head tag, that you can adjust to your needs.
Screenshots
"License"
This software is a gift from me to you. By accepting this gift, we're forming a relationship, and with that comes certain expectations. Namely:
- When you share this gift with others, you will share it in the same spirit as I share it with you.
- You will not use this gift to hurt people, any living creatures, or the planet