View Full Version : Guest Book - No Database

Apr 24th, 2007, 11:20 AM
I found this at hotscripts and it was about 10 files and a whole lotta includes and requires so I thoug I would bring it down to 3 files, 2 which you don't even see.

create a file on you directory named data.php and save it with NO CODING inside it.

create index.php and this code:

<style> @import "stylesheet.css"; </style>
<title> My Guest Book </title>

<div class="thread">
<?php include "data.php"; ?>

<div class="add">
<b>Add entry</b> <br/> <br/>

<form action="insert.php" method="post">
<input type="hidden" name="posted" value="yes">
Nickname: <input type="text" name="name"> <br/> <br/>
<textarea cols="50" rows="5" name="post">Enter Any Comment Here...</textarea> <br/>
<input type="submit" value="Submit">


And that will have your form and display your comments and finally all you need is the 2nd page you won't see.


$allowed_html_tags = "";
$addtotop = "1"; // This determines the order to display it. Leave for newest comments on top or change to 0 for oldest to newest.

// Checks if the user wants to view the form or add a entry
if (

// Make sure the script works if register_globals is off
$name = $HTTP_POST_VARS['name'];
$post = $HTTP_POST_VARS['post'];

// Process the Information Entered and Remove Stuff
$post = strip_tags($post, $allowed_html_tags); // Strip HTML
$post = stripslashes($post); // Strip Slashes

$time = date("F jS Y, h:iA");

if ($addtotop == "0" ) {

// Writes the user's entry to a file
$fp = fopen("data.php", "a");
fputs($fp, "<p><b>Posted by:</b> " . $name . "</p><p>" . $post . "</p><p><b>Time: </b>" . $time . "</p>");


if ($addtotop == "1" ) {

// Get all the current entries and put it in a string
$att1 = "data.php";
$att2 = fopen ($att1, "rb");
$currententries = fread ($att2, filesize ($att1));
fclose ($att2);

// Writes the user's post to a file
$fp = fopen("data.php", "w+");
fputs($fp, "<p><b>Posted by:</b> " . $name . "</p><p>" . $post . "</p><p><b>Time: </b>" . $time . "</p>" . $currententries);


header("Location: index.php?error=false");

} else {
header("Location: index.php?error=true");

feel free to add to the script. I can't say otherwise. :thumbsup:

Jul 10th, 2007, 02:32 PM
This is a great script. :) Is there anyone who could take the time and make it spamproof? So you had to include a word in the comment, that is not used by spammers? If the word is included in the comment, the comment will get posted and if not, it will be left out of course. And if the word is in the comment, it will get hidden...

Jul 10th, 2007, 02:49 PM
Also, I get this error the first time I try to post:

Warning: fread(): Length parameter must be greater than 0. in c:\programmer\easyphp1-8\www\insert.php on line 33

Warning: Cannot modify header information - headers already sent by (output started at c:\programmer\easyphp1-8\www\insert.php:33) in c:\programmer\easyphp1-8\www\insert.php on line 43

Then reload and suddenly there's two comments of the same. :confused:

Jul 19th, 2007, 10:33 PM
That's server problem, can't help you. I could make it spam proof, like a cookie for every 5 minutes you comment.

Sep 5th, 2007, 01:00 PM
Often what I find is a in a comments page people will strip_tags on a variable then send it straight to the database. This means that if a guy puts a link (<a href="#">naughty angels</a> you will still have that entry stored in the database. Here is a small php snippet to stop that from happening.

$message = "What ever you want it to be.";//From a form, whatever.
$message1 = strip_tags($message);
if ((strlen($message)) > (strlen($message1))){
$error = true;
echo("No tags allowed, fool");
} else {
//proceed with database addition, or whatever

Sep 5th, 2007, 01:05 PM
lol a guestbook only needs one file...

Just seems beond basic to me since I am developing a forums :P

Sep 5th, 2007, 01:27 PM
what? why? how?
this thread was made in april what was the point in bringing it back to life?

Sep 14th, 2007, 03:51 AM
im using that at my site thanks so much

Feb 26th, 2008, 11:34 PM
I noticed that at the bottom you made a reference to header index.php.

I am wanting to add the guest book to all my article pages I want the comments and form and article all to be on one page. Is this possible? thanks

Feb 27th, 2008, 08:25 AM
I have a problem here. I wonder if anyone can solve it? When i run the script on localhost, saving all files as a php extension where data.php has no codings and the rest of the files has it into a directory called example.php (directory as in a folder and folder.php :O) When i type Nickname as ASD and posted ASD text, there isn't any content displayed other than the time and posted by seems empty too! As well, i opened the data.php file, not a folder. I used Dreamweaver to save it as a php file and it seems to be able to display nothing except the time, etc!