Basic Comment Box Setup

I have a couple of PHP files that I downloaded in order to use as a comment box, for my website but I’m wondering what they are for.

The only one that displays a graphical interface is the one called Guestbook.php
A few other files came with it such as include.php and sign.php and I’m wondering why they are separate instead of just being in one single file called guestbook.php

I’ve figured out how to integrate a the guestbook into a div in my website and style it with CSS, but I’m still a little confused about how it works and what the other files for.

In one line of the code in guestbook.php I see something that says:

<?php include(“include.php”) ?>

I’m guessing that means that in order for guestbook.php to function correctly the include.php file must be linked to in much the same way that you can link your HTML to a stylesheet with the link rel=“” tag, correct?

I still don’t know what include.php does. So far when I submit a comment it appears to work. It takes me to a new page in my browser and the link shows:


I’m not sure how to access that page to view my comments, let alone moderate them and style them so I can change their font sizes, colors and what not.

Here’s the files that came with my scripts in the RAR package:

guestbook.txt…do I open this in a browser window (WTF?)




Can put a link to the files.

Without looking at the source of the files, we can only guess. But, here is my guess:

font.gdf - font file for use with the PHP gd image library (possibly for use with the captacha)
include.php - will include common functions etc
sign.php - the script used to sign the guestbook - ie, the form to add a comment etc.
guestbook.txt - I’m guessing this is where the guestbook data will be stored.

Are you having a specific problem with it? What actually is the problem you are having?

Hey there, here’s the links. I hope I’ve linked them correctly to you.

Thanks alot


Again, what is it you need to know? What question are you asking?

For PHP pages, you need to paste the code here between [ code ] [ /code ] tags

Hey sorry you posted while I was typing a message so I didn’t see your new post.

What I’m trying to do is find out how to view my comments, and once I figure that out, find a way to integrate that page into a div on the main comment page.

Here’s the code for GUESTBOOK.PHP:

if($_GET[“msg”] == “1”) echo “<span style=\“color: #f00\”><strong>ERROR: The maximum number of characters for a comment is 255. Your comment was <ins>”.$_GET[“l”].“</ins> characters.</strong></span><br /><br />”;
elseif($_GET[“msg”] == “2”) echo “<span style=\“color: #f00\”><strong>ERROR: Your comment cannot be added because a censored word ( <ins>”.$_GET[“cw”].“</ins> ) was detected.</strong></span><br /><br />”;
elseif($_GET[“msg”] == “3”) echo “<span style=\“color: #f00\”><strong>ERROR: You must enter the correct verification code.</strong></span><br /><br />”;
elseif($_GET[“msg”] == “4”) echo “<span style=\“color: #f00\”><strong>ERROR: You have already recently signed this guestbook.</strong></span><br /><br />”;
elseif($_GET[“msg”] == “5”) echo “<span style=\“color: #0f0\”><strong>Message Sent.</strong></span><br /><br />”;
<link rel=“stylesheet” type=“text/css” href=“styles.css” />
body {
background-color: #111111;
<title>Add a Comment</title>

<p class=“comment_text”>Pages:</p> <?php include(“include.php”) ?>

<form action=“sign.php” method=“post”>
<table bgcolor=“#009900” border=“0” cellpadding=“1” cellspacing=“10”>
<td valign=“top”>
<p class=“text”>Add a Comment</p>
<strong>Name</strong>:<br />
<input maxlength=“35” name=“name” size=“50” type=“text” /><br /><br />
<strong>E-mail</strong>:<br />
<input maxlength=“125” name=“email” size=“50” type=“text” /><br /><br />
<strong>Web Site Address</strong>:<br />
<input maxlength=“125” name=“uri” size=“50” type=“text” value=“http://” /><br /><br />
<strong>Message</strong>:<br />
<textarea cols=“48” name=“message” rows=“5”></textarea>
<br />
<strong>Verification Code</strong>:<br />
<img alt=“” src=“captcha.php” title=“” /><br /><br />
<strong>Type Verification Code (Required)</strong>:<br />
(Five characters, case sensitive)<br />
<input maxlength=“5” name=“verification” size=“5” type=“text” /><input name=“check” style=“visibility: hidden” type=“checkbox” value=“1” /><br /><br />
<input type=“image” src=“” /><br />
<br />
<strong>:)</strong> <img alt=“:)” src=“smile.gif” style=“padding: 0 15px 0 3px; vertical-align: middle” title=“:)” /> <strong>:(</strong> <img alt=“:(” src=“frown.gif” style=“padding: 0 15px 0 3px; vertical-align: middle” title=“:(” /> <strong>;)</strong> <img alt=“;)” src=“wink.gif” style=“padding: 0 15px 0 3px; vertical-align: middle” title=“;)” /> <strong>:D</strong> <img alt=“:D” src=“happy.gif” style=“padding: 0 15px 0 3px; vertical-align: middle” title=“:D” /> <strong>:P</strong> <img alt=“:P” src=“tongue.gif” style=“padding: 0 15px 0 3px; vertical-align: middle” title=“:P” /> </td>

I’ve been able to link it to my stylesheet and customize it, but when I make a comment on my comment page and hit submit, I get taken to a slightly different page altogether…it’s the confirmation page and is no longer in a div. I’d like to be able to simply have it not take me anywhere at all and just remain at the art gallery (comment page).

Here’s the other files:



$guestbook_file = "guestbook.txt";
$lines = file($guestbook_file);
$total_entries = count($lines);

$page = 1;
else {
$page = $_GET["page"];

$sum = $total_entries / 5;
$floor = floor($sum);
if($sum == $floor) {
$pagenumber = $floor;
else {
$pagenumber = $floor + 1;

if($page &gt; 1) {
echo "&lt;a href=\\"".$PHP_SELF."?page=".($page - 1)."\\"&gt;&laquo;&lt;/a&gt; ";
else {
echo "&laquo; ";
for($i = 1; $i &lt;= $pagenumber; $i++) {
if($i == $page) {
echo $i." ";
else {
echo "&lt;a href=\\"".$PHP_SELF."?page=".$i."\\"&gt;".$i."&lt;/a&gt; ";
if($page &lt; $pagenumber) {
echo "&lt;a href=\\"".$PHP_SELF."?page=".($page + 1)."\\"&gt;&raquo;&lt;/a&gt; ";
else {
echo " &raquo;";

echo "&lt;br /&gt;&lt;br /&gt;

<hr /><br />


$lines = file($guestbook_file);
$total_entries = count($lines);

$page = 1;
else {
$page = $_GET["page"];
$minimum = 5 * ($page - 1);
$maximum = 5 * $page - 1;

foreach($lines as $line_number =&gt; $line) {
if($line_number &lt; $minimum) {}
elseif($line_number &gt; $maximum) {
else {
$entrynumber = $total_entries - $line_number;
echo $line;


And this one is for SIGN.PHP:



$date_format = "F d, Y";
$time_format = "h:i:sa";

$guestbook_file = "guestbook.txt";
$guestbook_page = "guestbook.php";
$html_allowed = false; // Change this to true if you want to allow HTML to be posted

// What is displayed if the fields are left blank when an entry is added

$blank_name = "Anonymous";
$blank_email = "Email Hidden";
$blank_uri = "No Webpage Yet";
$blank_message = "N/A";

// Begin censored word filter
// A lot of these words were acquired from bots posting spam links in my guestbook
// Feel free to remove or add words as you wish

$filter = array(".biz", ".info", "adipex", "adult", "affiliat", "afford", "allegra", "ambien", "*******", "baccarat", "black jack", "blackjack", "bontril", "breast", "carisoprodol", "carookee", "casino", "cell", "cheap", "check", "cialis", "cigar", "claritin", "clit", "cok", "commerc", "credit", "cum", "****", "dating", "debt", "dexone", "diet", "dildo", "discount", "drug", "dvd", "ebay", "ephedra", "erection", "fck", "fock", "fuk", "gambl", "gift", "health", "hentai", "homo", "horo scope", "horoscope", "hotbox", "hotel", "idiot", "insuran", "incest", "ipod", "join", "keno", "lesbian", "levitra", "license", "lipitor", "lottery", "master card", "mastercard", "masturbat", "medic", "member", "meridia", "mortgage", "movie", "mp3", "nigg", "nokia", "nude", "offer", "onsize", "paxil", "pedo", "pharm", "phent", "phone", "pill", "play", "poker", "prescription", "product", "prozac", "ps2", "ps3", "psp", "purchase", "pussy", "requip", "reward", "ring tone", "ringtone", "roul", "screen saver", "screensaver", "serial", "shop", "slot", "soft ware", "software", "soma", "sponsor", "sprint", "suck", "ticket", "tourna", "tramadol", "travel", "ultram", "url=", "vagina", "valium", "verizon", "vernulsa", "viagra", "visa", "voyeur", "wall paper", "wallpaper", "web cam", "webcam", "weight", "xanax", "xbox", "xxx", "zoloft", "zyrtec");

// End censored word filter

// Begin functions

function remove_tags($source) {
$source = strip_tags($source);
return preg_replace('/&lt;(.*?)&gt;/ie', "'&lt;'.'\\\\1'.'&gt;'", $source);

function word_wrap($message) {
$cut = " ";
$max_length = 60;
$result = "";
$word_length = 0;

// End functions

$length = strlen($message);

$tag = FALSE;
for($i = 0; $i &lt; $length; $i++) {
$character = substr($message, $i, 1);
if($character == "&lt;") {
$tag = TRUE;
elseif($character == "&gt;") {
$tag = FALSE;
elseif(!$tag && $character == " ") {
$word_length = 0;
elseif(!$tag) {
if(!$tag && !($word_length%$max_length)) {
$character .= $cut;
$result .= $character;
return $result;

// Begin field manipulation

$layout = "&lt;strong&gt;!date!&lt;/strong&gt; at &lt;strong&gt;!time!&lt;/strong&gt;&lt;br /&gt;

<em><small>!ipaddress! * *</small></em><br />
!name!, <a href=\“mailto:!email!\” title=\“Email\”>Email</a>, <a href=\“!uri!\” title=\“Web Site\”>Web Site</a><br />
!message!<br /><br />";

$_POST["message"] = str_replace("

“, “<br />”, $_POST[“message”]);
$message = word_wrap(remove_tags($message));
$message = stripslashes($_POST[“message”]);
$message = str_replace(array(”&“, “\r
“), array(”&”, " “), $message);
$message = str_replace(array(”&gt;”, “&lt;”, “\r
“), array(”>”, “<”, “<br />”), $message);

if($html_allowed == false) {
$message = str_replace(array("&lt;", "&gt;"), array("&lt;", "&gt;"), $message);
$message = strip_tags(stripslashes($_POST["message"]));

$name = strip_tags(stripslashes($_POST["name"]));
$email = urlencode(strip_tags(stripslashes($_POST["email"])));
$uri = urlencode(strip_tags(stripslashes($_POST["uri"])));
$uri = str_replace(array("%2F", "%3A"), array("/", ":"), $uri);

$ip = explode(".", $_SERVER["REMOTE_ADDR"]);
$display_ip = $ip[0].".".$ip[1];

if(trim($name) == "") $name = $blank_name;
if(trim($email) == "") $email = $blank_email;
if(trim($uri) == "") $uri = $blank_uri;
if(stristr($uri, "http://") === false) $uri = "http://".$uri;
if(trim($message) == "") $message = $blank_message;

$transition = $layout;
$variables = array("\

“, “!name!”, “!email!”, “!uri!”, “!message!”, “!date!”, “!time!”, “!ipaddress!”);
$input = array(”", $name, $email, $uri, $message, date($date_format), date($time_format), $display_ip);

$input = str_replace(":)", "&lt;img alt=\\":)\\" src=\\"\\" style=\\"vertical-align: middle\\" title=\\":)\\" /&gt;", $input);
$input = str_replace(":(", "&lt;img alt=\\":(\\" src=\\"\\" style=\\"vertical-align: middle\\" title=\\":(\\" /&gt;", $input);
$input = str_replace(";)", "&lt;img alt=\\";)\\" src=\\"\\" style=\\"vertical-align: middle\\" title=\\";)\\" /&gt;", $input);
$input = str_replace(":D", "&lt;img alt=\\":D\\" src=\\"\\" style=\\"vertical-align: middle\\" title=\\":D\\" /&gt;", $input);
$input = str_replace(":P", "&lt;img alt=\\":P\\" src=\\"\\" style=\\"vertical-align: middle\\" title=\\":P\\" /&gt;", $input);

if(strlen($message) &gt;= 260) {
header("Location: ".$guestbook_page."?page=1&msg=1&l=".strlen($message));

if(strlen($name) &gt;= 36 || strlen($email) &gt;= 126 || strlen($uri) &gt;= 126) {
header("Location: ".$guestbook_page."?page=1");

if($_POST["verification"] != $_SESSION["veri"] || $_POST["verification"] == "") {
header("Location: ".$guestbook_page."?page=1&msg=3");

if($_COOKIE["guestbook_signed"] == "true") {
header("Location: ".$guestbook_page."?page=1&msg=4");

if($_POST["check"] == "1") {
header("Location: ".$guestbook_page."?page=1");

// End field manipulation

$transition = str_replace($variables, $input, $transition);

$past_entries = @fopen($guestbook_file, "r");
$content = @fread($past_entries, filesize($guestbook_file));

$cw_check = $transition;

foreach($filter as $censored_word) {
if(stristr($cw_check, $censored_word)) {
header("Location: ".$guestbook_page."?page=1&msg=2&cw=".$censored_word);

$new_entry = $transition."\


$all_entries = @fopen($guestbook_file, "w");
@fwrite($all_entries, $new_entry);

setcookie("guestbook_signed", "true", time()+2419200);

header("Location: ".$guestbook_page."?page=1&msg=5");


If you need Captcha.php let me know.

OK, it looks like include.php is intended to be included by you where you want the comments to appear. The bottom end of that page is outputting the lines in the guestbook - where it says ‘echo $line’ is where you need to change if you want extra HTML to be output with the lines (eg putting each one in a <p> tag or something).

You need to <?php include(‘include.php’); ?> where you want the lines to appear. Styling can be done with CSS once you put some HTML around the lines to hook into. The top part of that file handles the pagination.

For future reference, use [ code ] or [ php ] tags to paste PHP code, [ quote ] doesn’t format it correctly.



So that’s what include.php is for…alright I’ll have to give that a try and will post my results. Thanks for the help. And I think I’m getting sick of all these emoticon faces after my last post, aren’t you? Hahaha

Ok so in the file our_gallery2.html I put

<?php include('include.php'); ?>

and I changed

echo $line;


echo $line our_gallery2.html;

which had no effect so I figure my syntax was wrong and I tried

echo $line >> our_gallery2.html

Am I misunderstanding how to manipulate the echo $line?

yes, echo just outputs to the screen, you don’t echo something to a file. Leave the echo line as it is.

It seems you could learn a bit by reading up a bit on - the beginners tutorial can be found here:

That’s one of the tuts I’ve been reading…thanks for the link I’m gonna keep at it!