...

View Full Version : Guest Book - No Database



GSimpson
04-24-2007, 12:20 PM
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:



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

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

<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/>
Post:<br/>
<textarea cols="50" rows="5" name="post">Enter Any Comment Here...</textarea> <br/>
<input type="submit" value="Submit">
</form>
</div>

</body>
</html>


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

insert.php


<?php
$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 (
$_SERVER['REQUEST_METHOD'] == 'POST' ) {

// 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>");
fclose($fp);

}

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);
fclose($fp);

}

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:

Jutlander
07-10-2007, 03: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...

Jutlander
07-10-2007, 03: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:

GSimpson
07-19-2007, 11: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.

idalatob
09-05-2007, 02: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.


<?php
$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");
exit;
} else {
//proceed with database addition, or whatever
}
?>

Lightro
09-05-2007, 02:05 PM
lol a guestbook only needs one file...

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

rafiki
09-05-2007, 02:27 PM
what? why? how?
this thread was made in april what was the point in bringing it back to life?

Bhodio
09-14-2007, 04:51 AM
im using that at my site thanks so much

zeplin
02-27-2008, 12:34 AM
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

FlyFree
02-27-2008, 09: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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum