Ultimate Guestbook Tutorial: How to build a Guestbook with a honeypot, error checking, IP banning, pagination, e-mail notification and smilies with PHP and mySQL

Ultimate Guestbook Tutorial: How to build a Guestbook with a honeypot, error checking, IP banning, pagination, e-mail notification and smilies with PHP and mySQL

I will get started with this tutorial straight away. So lets build some HTML to show our form. We will do the HTML for displaying the posts of the guestbook at a later stage. So in order to make our form do this:

1. Make a new folder somewhere on your webserver and call it templates. I am working in the folder called guestbook, so it looks like ‘/home/guestbook/templates/’.

2. Next make a file in the templates folder and call it form.php.

3. Open up the file and put this code in:

<form name="guestbook" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="guestbookform">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td valign="top">Name:*</td>
		<td valign="top"><input type="text" name="name" /></td>
	</tr>
	<tr>
		<td valign="top">E-Mail:*</td>
		<td valign="top"><input type="text" name="email" /></td>
	</tr>
	<tr>
		<td valign="top">Website:</td>
		<td valign="top"><input type="text" name="website" /></td>
	</tr>
	<tr>
		<td valign="top" colspan="2">Message:</td>
	</tr>
	<tr>
		<td valign="top" colspan="2"><textarea name="message"></textarea></td>
	</tr>
	<tr>
		<td valign="top" colspan="2" align="center"><input type="submit" name="submit" value="Sign Guestbook" /></td>
	</tr>
</table>
</form>

This code should be fairly self explanatory. Most of it is just simple HTML code that first declares how the browser passes data to the server (POST) and sets up the user interface elements. The only php in this code is in the action of the form, which tells where the browser should send the request to:

<?php echo $_SERVER['PHP_SELF']; ?>

This simply accesses a predefined PHP variable, which spits out the location where the user currently is. So if you were looking at the page we made in the browser it would output ‘form.php’.

Now if you just looked at the form.php page in your browser you will notice it looks bad. Lets get into the styling of the form before we start giving it some functions. We will achieve this by using a main skin template. This can be achieved simply through a file called skin.php which allows you to simply add bits of code to different sections of the HTML.

Posted by VoiDeT

Categorised under PHP
Bookmark the permalink or leave a trackback.

60 Comments

  1. CGar

    Hello VOIDET

    I spent last night going through this tutorial and it was great and informative.

    One question I have is that I see your guestbook example has had some spambot action. Is this because there are new techniques that your tutorial doesn’t cover? I’d like to keep this kind of crap off my guest book if possible.

    Thanks for your great tutorial and your feedback.

    Best,
    CGar

    August 3, 2009 @ 3:43 am
  2. VoiDeT

    Hey Cgar,

    This is both true and unfortunate.
    I only taught one spam catching technique.
    However more can be applied if need be. Generating a captcha form, or having an ip-ban with 30 day cool off period. Running known ip blocking from black lists.
    The honey pot technique is just one! Surprisingly, it rejects quite alot!

    Let me know if i can help you out further!
    VoiDeT

    August 3, 2009 @ 4:48 pm
  3. Dennis van Duinen

    Hi there,

    A great tut! Im trying to put it on my site.

    But there is one little problem. The honeypot.. when is add this link:

    a new text field appears on my guestbook, while you where saying that it was hidden?

    How is that possible?

    Dennis

    November 12, 2009 @ 10:40 pm
  4. Hi there. Thanks for the great tut. Sorry…forgot to read the last side, as I didn’t used all of the tut for my guestbook at the moment. So I implemented the guestbook in my website without asking you first. And…I’m not completly ready, still working on some things as the honeypot and the pagination.

    December 6, 2009 @ 8:39 am
  5. Hello VOIDET,

    This is the best tutorial on the internet so far! :D

    I’m stuck at stage 7 – 10,
    it looked fine until stage 7 then the succes-message never showed up. :(

    The IP thing didin’t work for me :/ so I jumped that part and now I’m trying to get the entries to work out, but it show me this message:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\guestbook\templates\entries.php on line 6

    do you have a idea of what’s wrong?
    I would be happy for any help, just contact my email!

    Regards Zime

    December 20, 2009 @ 11:02 pm
  6. VoiDeT

    @Zime:
    Thanks a lot for the kind words.
    That’s a shame that you can’t get the guestbook working. It looks as though your data isn’t being insert correctly. What you can do however is check your database for any records. If they aren’t in there then check what’s going on with data you’re inserting, and the insert commands.
    If you do see the data in there, then check what’s happening when you try and retrieve the records.

    I’m thinking i might rewrite this tutorial to use OOP with PHP5.
    Or maybe save that for a whole new tutorial.

    December 21, 2009 @ 1:45 pm
  7. Hi
    First great thanks to the author of this tutorial/workshop

    Its working great. But there is only a single problem with the website links in the db entrys they re not working.

    The link includes the hole file path i.e.(http://htdocs/mywebsite/www.pcsh.it) whats wrong?

    thx in advance and best regards
    Oli

    January 29, 2010 @ 4:37 am
  8. Robin

    THX a lot

    love this tut

    March 31, 2010 @ 11:22 pm
  9. ome tony

    hey, where can i find the turtorial?

    greetings

    June 1, 2010 @ 10:55 pm
  10. Dude, many thanks for this nice and clean tutorial. Took me about an hour to read it all up and add own commands.

    July 12, 2010 @ 12:13 am

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

or