inside the mind of Wattz

Security Image (captcha)

I have created a class to easy the pain of generating captcha functionality on your registration (and what ever else) pages. Its a simple class and easy to use.

You can download here: Wattz.net Download Page

Requirements:
- Php5+ (with GD enabled)
- GD

Usage:

$width = 100;
$height = 80;
$Chars = 8; //number of characters.
$lines = 100; //number of background lines.
$SecurityImage = new SecImg($width, $height, $Chars, $lines);
$SecurityImage->Create();
Here is an example setup for complete usage:

::::::::: USER REGISTRATION PAGE:

<form>
….
<img src=”securityImage.php”>
<input type=”text” name=”securityCode”>

<input type=”submit” value=”submit”>

</form>

:::::::::: Now for SecurityImage.php

<?php
session_start();
include(“securityImageClass.php”);

$img = new SecImg(100,40);
$img->Create();

$_SESSION['securityCode'] = $img->code;

?>

:::::::::: Then you can validate in your registration page processing script like

<?php

session_start();

if($_POST['securityCode'] != $_SESSION['securityCode'])
{
die(“Security Code does not match”);
}

?>

Like I said, that is an example, there are many ways to do it. Well I hope you find this useful and I look forward to contributing more in the future.

_Wess

2 Comments

2 responses so far ↓

Leave a Comment