authImage
What is it ?
So, let's say you own a website and you've got a simple contact form. Everyday you get tons of emails from spam scripts and you want to stop it. What you need is a clever mechanism, which will tell apart human from a machine. The best way, and very popular one, is to use an image with special code drawn on it. Humans can read it, machines cannot. But probably you don't know how or don't have the time to write it ? Don't worry, I have done it for you :).
What will you need ?
PHP with a support for GD library and... that's all. No database needed ? Nope, it does not keep any records, create files, whatsoever. So how does it work you ask ? Don't, it just do ;) Of course if you're so curious, you can see the code for yourself.
How does it work ?
See for yourself, just go to the example page.
How to use it ?
You have no idea how simple it is. You need to write only few lines of code! So, let's implement a simple html form and a php file to validate it. Firstofall you need to create a script to generate an image. You do it with only 3 lines of code (see image.php):
<?
require('class.authImage.php');
$ai = new authImage();
$ai->createImage();
?>
Next you need to create a simple form (see index.html):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">
<meta name="Author" CONTENT="Cezary Piekacz :: Cezex">
<meta http-equiv="Reply-to" CONTENT="cezex@redfish.DELETETHIS.pl">
<title>authImage Class</title>
<meta name="Description" CONTENT="authImage Class">
</head>
<body>
<form method="POST" action="validate.php">
Enter code from the image below:<br />
<input type="text" name="auth_code" size="6" maxlength="6">
<img src="image.php" width="100" height="30"><br /><br />
<input type="submit" value="Validate code">
</form>
</body>
</html>
Finaly, the validation file to check if data entered in a form is done by user or a script:
<?
require('class.authImage.php');
$ai = new authImage();
if ($ai->validateAuthCode($_POST[auth_code])) {
echo 'Entered code is correct.';
}
else {
echo 'Entered code is incorrect.';
}
?>
And that's all, you're done! If you have any suggestions for a new version just send me an e-mail.
Download
authImage v0.4 [81 kB]
* 2008-05-27
+ changed authentication method; now there is a simple equation printed on the image (for example 3+7) so you must enter result of it not just rewrite text
authImage v0.3 [81 kB]
* 2006-11-10
+ added parameter to set background color as transparent - $class->setBgColor('#FFFFFF', true)
+ changed method which draws colors for characters, now it will always be much different than the background
authImage v0.2 [81 kB]
* 2006-11-07
+ characters 0, o, 1, l, 2 and z are removed from generated code
+ all letter from entered code are lowered (just in case)
+ changed variable name from $auth_code to $cookie_code (caused problems on some configurations)
+ modyfied function to check authorization code
+ added method to change color of image's background
authImage v0.1 [80 kB]
* 2006-09-20
* first public version made