Sponsor
Now Playing
- Alix Perez – I'm Free 2 hours ago
- Alix Perez – Intersections 2 hours ago
- Alix Perez – Forsaken 2 hours ago
- Glen E Ston – Ouroboros (Original Mix) 3 hours ago
- Black Sun Empire – Everything 3 hours ago
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
April 26, 2008,
47,482 views
If you don’t know what smilies are, then please give me the address of the rock that you live under. Smilies are those little graphics that popup in replacement of a textual smiley, like:
![]()
:O
) ^__^ (>0_o)>
This is a guestbook tutorial, so expect people to be posting some smilies. We will making a smilies function to take care of the smilies replacement. Functions are basically code that sit outside of your main program. They do only a certain job, and operate via code in our main application sending information to them and then information getting returned. Think of functions as worker bees. You give them a job, and they return to you with something. Lets get started!
In your includes folder make a file called functions.php. Next in your index.php file do:
Under:
include('includes/config.php');
Add:
include('includes/functions.php');
You should understand what include statements do now. Open up your functions.php page and add:
<?php
function smilies($text){
$smilies = array(':)', ':o', ':O', ':D', ':bounce:', ':(', ':yay:', ':love:', ':shout:');
$images = array('<img src="templates/smilies/smile.gif" />', '<img src="templates/smilies/bigsmile.gif" />','<img src="templates/smilies/bigsmile.gif" />','<img src="templates/smilies/bigsmile.gif" />', '<img src="templates/smilies/bounce.gif" />', '<img src="templates/smilies/sad.gif" />', '<img src="templates/smilies/yay.gif" />', '<img src="templates/smilies/love.gif" />', '<img src="templates/smilies/shout.gif" />');
$text = str_replace($smilies,$images,$text);
return $text;
}
?>
This basically sets up our function. You declare a function with ‘function’ then the name of the function. The bit in brackets is what the function accepts and stores it in its own value. For example we will be sending this function the message text, so the message text will be stored in the value $text. You can send functions more parameters, just separate them with commas.
The next line we have a list of all the smilies we will accept. Nothing special really. The next line is the $images line. Its in order with the above array of smilies, so that when they get replaced, we slot in the right image. Its merely HTML code we replace the text with. The work horse here is:
$text = str_replace($smilies,$images,$text);
This compares both arrays, searching for the smiley text and replacing it with the images array. Then it stores it back into the $text variable. The next line returns the value of $text back to the caller. We haven’t set up the caller yet! So lets go and open entries.php and:
Find:
<?php echo stripslashes($row['message']); ?>
Replace with:
<?php echo smilies(stripslashes($row['message'])); ?>
We have our smilies function, sending the contents of the message to the smilies function! When the function is complete it sends it back here and then will be echoed to the screen! Amazing stuff. You can of course expand the smilies yourself, i just did it quickly. You will of course need to make sure you have the smilies images on your server. I made a folder in templates called smilies and dropped the smilies in there.
You can of course do the same with swear words, simple find and replace! I won’t do it here, we need to get going on finishing the tutorial! Plus freedom of speech
60 Comments
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
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
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
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.
Hello VOIDET,
This is the best tutorial on the internet so far!
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
@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.
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
THX a lot
love this tut
hey, where can i find the turtorial?
greetings
Dude, many thanks for this nice and clean tutorial. Took me about an hour to read it all up and add own commands.