Adding a CAPTCHA to BellaBook3.2
By popular request, this tutorial will explain how to add a captcha to BellaBook3.2 to help in the campaign against spam.
First, you need to make a captcha image background in jpg format. Alternatively you can download one I've made for you. About 100 pixels by 30 pixels should be sufficient.
Next, create a file called captcha.php. Copy and paste the following in to it (with no spaces at the top or bottom):
<?php
session_start();
$md5 = md5(microtime() * mktime());
$string = substr($md5,0,5);
$captcha = imagecreatefromjpeg("captcha.jpg");
$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha,233,239,239);
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);
imagestring($captcha, 5, 20, 10, $string, $black);
$_SESSION['key'] = md5($string);
header("Content-type: image/jpeg");
imagepng($captcha);
?>
Next, open sign.php and at the top, find:
<?php
@include('header.php');
if ((isset($_GET['page'])) && ($_GET['page'] == "process")) {
..replace it with:
<?php
if ((isset($_GET['page'])) && ($_GET['page'] == "process")) {
session_start();
if(md5($_POST['captcha']) != $_SESSION['key']) {
setcookie(session_name(), '', time()-36000, '/');
$_SESSION = array();
session_destroy();
echo "<p>The text you entered didn't match the image, please <a href='sign.php'>try again</a>.</p>";
exit;
}
if (isset($_SESSION['key']) && isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-36000, '/');
$_SESSION = array();
session_destroy();
}
@include('header.php');
At the bottom of the file (sign.php), find:
} else {
?>
..and replace it with:
} else {
@include('header.php');
?>
Lastly, still in sign.php — near the bottom of the file, find:
<textarea name="comments" id="comments"></textarea> <label for="comments">Comments</label> <br />
After it, place:
<img src="captcha.php" alt="" style="margin-bottom: 2px;" /><br />
<input type="text" name="captcha" id="captcha" /> <br />
Save sign.php and upload it, along with captcha.php and captcha.jpg — your captcha test should now appear on the sign page and will help prevent spam.
Tags:
bellabook, script-modding, captcha,
Last Updated On: 22nd June 06 by Jem
Bookmark At: StumbleUpon, Digg

Handy Stuff
Downloads
Friends of 'TT'
Resources