PHPBuilder - annotate

RSS Twitter
Snippets Bbs Discussion


by: Steve Yelvington
August 13, 2000

Version: 1

Type: Sample Code (HOWTO)

Category: BBS/Discussion

License: Artistic License

Description: This script, which is just a few lines long not counting the comments, illustrates how simple it is to support basic discussion or guestbook services using PHP (without a database). Your Web server must have permission to write to the directory. For a working example, see:



This is a module that can be placed on any php3 page to allow users to add
their comments. The comments are stored in a file in the current directory,
whose name is constructed by adding ".comment" to the calling page's name,
and merged into the calling page dynamically. (The calling page is not

I wrote this because I wanted a simple way to add this functionality to my
pages without requiring that mySQL be available.

In the message input, blank lines are converted to paragraph tags. No other
conversions are applied. If you don't want your users to be able to input
html, uncomment the "strip_tags" line.

Note that the directory must be writable by the web server.

Put this module in some convenient location and then embed it in your pages
like so:

or, relative to the docroot:
require($DOCUMENT_ROOT . "/relativepath/php3");

Steve Yelvington <>

if ($message)
	/* uncomment the next two lines to strip out html from input */
	/* $name = strip_tags($name); */
	/* $message = strip_tags($message); */
	$message = ereg_replace("\r\n\r\n", "\n<P>", $message);
	$date = date("l, F j Y, h:i a");
	$message = "<B>$name </B> -- $date<P> $message <BR><HR>";
	$fp = fopen (basename($PHP_SELF) . ".comment", "a");
	fwrite ($fp, $message);
	fclose ($fp);
@readfile(basename(($PHP_SELF . ".comment")));
<FORM method="post">
<b>Your name:</b><BR><INPUT name="name" type="text" size="55"><BR>
<b>Your comment:</b><BR><TEXTAREA name="message" rows=10 cols=55 wrap=virtual>
<INPUT name="submit" type="submit" value="Post your comments">

Comment and Contribute

Your comment has been submitted and is pending approval.

Steve Yelvington



(Maximum characters: 1200). You have characters left.