I don't know of any good script, so I simply wrote some code on my own.
Create a file called
functions.php on your server and copy this code to it:
Code:
<?
function captcha_check($action)
{
///////////////////// Change these settings /////////////////////
// The fonts to use. Change to any fonts you like, you can even
// add as many as you like.
$fonts = array("baveuse3.ttf","international.ttf","no_problem.ttf");
// Background images to write text on. Make sure they are JPG files!
// The pictures should be 160x50 in size.
$pictures = array("1.jpg","2.jpg");
// Set this to a secret word only you know about. Letters and numbers
// are both OK!
$secretword = "set this to a secret word only you know about";
////////////////// No more changes are needed ///////////////////
$txt = substr(md5($_SERVER[REMOTE_ADDR] ." ". date('d') ." ". date('m') ." ". date('h') ." ". $secretword),3,5);
if ($action == "img")
{
Header("Content-type: image/jpg");
$numpic = rand(0,(count($pictures)-1));
$im = imagecreatefromjpeg($pictures[$numpic]);
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
$i = 0;
while ($i < 5)
{
$angle = 15 - rand(0,40);
$fnum = rand(0,(count($fonts)-1));
$font = $fonts[$fnum];
$fontsize = 25;
ImageTTFText($im,$fontsize,$angle,($i * 30 + 5),36,$black,$font,substr($txt,$i,1));
$i++;
}
Imagejpeg($im);
ImageDestroy($im);
}
else
{
if ($txt == $action)
{
return 1;
}
else
{
return 0;
}
}
};
?>
Include functions.php in any file where you want to do the check, then create a new file called
image.php:
Code:
<?
include("functions.php");
captcha_check("img");
?>
Image will simply show the image to the end users so whereever you want to show the image you simply add:
Code:
<IMG SRC="image.php" BORDER=0 ALT="Fill in the numbers and letters you see in this picture in the field below" /><BR />
Here's a sample script that will ask the user for some letters and numbers. If the users enters the correct letters a short message show up:
Code:
<?
include("functions.php");
if ($_POST['do'] == "check")
{
// Do the check if the user entered the same numbers/letters as the picture.
if (captcha_check($_POST['letters']))
{
// The user wrote correct combination of letters and numbers
echo '<P><STRONG><FONT COLOR=green>You entered the correct text!</FONT></STRONG></P>';
}
else
{
//Sorry, please try again.
echo '<P><FONT COLOR=red>Sorry, wrong text! Try again.</FONT></P>';
}
}
?>
<FORM METHOD=post ACTION="<? echo $_SERVER[PHP_SELF]; ?>">
<INPUT TYPE=hidden NAME=do VALUE=check>
<IMG SRC="image.php" BORDER=0 ALT="Fill in the numbers and letters you see in this picture in the field below" /><BR />
<B>Fill in the numbers and letters you see on the picture above:</B><BR>
<INPUT TYPE=text NAME=letters SIZE=5><INPUT TYPE=submit VALUE="Submit!">
</FORM>
You can see this example live at
http://www.sampleaddress.com/captcha/index.php
/Andreas