Guestbook

A simple guestbook for dokuwiki 8-). The guestbook creates a dokuwiki page, so there is no need for a MySQL database. A live example can be found here.

Code

add_guestbook.php (Updated 10 Nov 2007)

The following PHP script will add the new comment to the beginning of the guestbook page. You should change $guestbook_location to the location of that page. If you place add_guestbook.php in the /inc folder of your dokuwiki installation ”../data/pages/guestbook.txt” will point to the page folder. Header, PHP and HTML tags are replaced for (a little) damage control >__>. Also a guest can only sign the guestbook ones every session to prevent spamming.

The page will be parsed by the dokuwiki parser so all other tags are available.

Change date(“d-m-y H:i:s”) to match your own date format. Change $redirect_location to the location the where the users will be redirected after signing the guestbook (guestbook.txt would be a good idea)(NO RELATIVE LINKS).

<?php
$guestbook_location = "../data/pages/guestbook.txt";
$redirect_location = "http://greenbird.info/dokuwiki/doku.php?id=guestbook";
session_start();
if(isset($_SESSION['posted'])){
    echo "For spam control you can only post once every session!";
    exit;
}
 
if($_POST['comment'] == "")
    exit;
 
$name = $_POST['name'];
if($name == "")
    $name = "Anonymous";
 
$needle = array("\n",
                "======",
                "=====",
                "====",
                "===",
                "==",
                "<php>",
                "<html>",
                "</php>",
                "</html>");
 
$str = array("\n>",
             "= = = = = =",
             "= = = = =",
             "= = = =",
             "= = =",
             "= =",
             "< php>",
             "< html>",
             "</ php>",
             "</ html>");
 
$name =  str_replace($needle, $str, $name);
$country = str_replace($needle, $str, $_POST['country']);
$comment =  str_replace($needle, $str, $_POST['comment']);
 
$handle = fopen ($guestbook_location, "r");
$contents = fread ($handle, filesize($guestbook_location));
fclose ($handle);
 
$new_comment = 
"//Name: **".$name."**//\\\
//Country: ".$country."//\\\
//Date: ".date("d-m-y H:i:s")."//\\\
>".$comment."
 
----
 
";
 
$new_comment = $new_comment.$contents;
 
$handle = fopen ($guestbook_location, "w+");
if(!fwrite($handle, $new_comment)){
  header("Location: ".$redirect_location);
  exit;
}
fclose ($handle);
 
$_SESSION['posted'] = 1;
header("Location: ".$redirect_location);
?>

Add guestbook wiki page

The following code will create a form so users can actually sign the guestbook.

<html>
<form action="./inc/add_guestbook.php" method="post">
<table border=0>
<tr><td>Name:</td><td><input type="text" name="name" maxlength=50 size=50 /></td></tr>
<tr><td>Country:</td><td><input type="text" name="country" maxlength=50 size=50 /></td></tr>
<tr><td>Message:</td><td><textarea name="comment" cols=50 rows=10></textarea></td></tr>
</table>
<input type="submit" value="Sign!" \>
</form>
</html>

Download

You can download add_guestbook.php here: add_guestbook.php (2 kB).

A new version with captcha image and bad word filter (more info here):
guestbook_captcha.rar (99.5 kB)
guestbook_captcha.zip (107.6 kB)

dokuwiki/guestbook.txt · Last modified: 2008/06/04 00:09 (external edit)
Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0