<?php
/*============================================================
php anti spam validation code ver. 0.4
--------------------------------------------------------------
(c) 2007 Arie Firmansyah
Website: http://tanpa.info
License: Freely copy & use, but include this notice.
--------------------------------------------------------------
This script is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability of fitness for a particular purpose.
--------------------------------------------------------------
question, bugs, support, idea or money :)?
contact me from email or website contact form.
==============================================================*/
/*============================================================
HOW TO USE THIS SCRIPT??
==============================================================
first, sorry my poor english lang.
1. your PHP must support GD
2. Insert validimgttf function on your script where you will
need antispam validation code
insert like: <img src=imgval.php />
//=============== start validimgttf function ================
function validimgttf() {
session_start();
$digit = $_SESSION['digit'];
$userdigit = $_POST['userdigit'];
session_destroy();
if (($digit == $userdigit) && ($digit > 1)) {
return true;
} else {
return false;
}
}
//================ end validimgttf function =================
For mor explicit:
please see sample file validation test (test_validation.php)
*/
$image = imagecreate(90, 35); // image size
$backgroundcolor = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); //background of image validation color
//this array for font color, you can change and add what you want.
$fontcolor = array (
imagecolorallocate($image, 0xFF, 0x00, 0x00),
imagecolorallocate($image, 0xFF, 0xDD, 0x00),
imagecolorallocate($image, 0x4D, 0xB9, 0x32),
imagecolorallocate($image, 0x00, 0xB2, 0xFF),
imagecolorallocate($image, 0xCB, 0x00, 0xFF)
);
//this array for font file, you can change and add what you want.
// this files (.ttf files) must exist and stored on same directorey imgval.php
$fontsarray = array (
"01.ttf",
"02.ttf",
"03.ttf",
"04.ttf",
"05.ttf"
);
//logical random...
srand((double)microtime()*1000000);
for ($i = 0; $i < 5; $i++) {
$cnum[$i] = rand(0,9); }
$rand_key = array_rand($fontsarray,count($fontsarray));
$rand_fontcolor = array_rand($fontcolor,count($fontcolor));
imagettftext($image ,18 ,-1 ,3 ,30 ,$fontcolor[$rand_fontcolor[0]], $fontsarray[$rand_key[0]], "$cnum[0]");
imagettftext($image ,18 ,3 ,20 ,30 ,$fontcolor[$rand_fontcolor[1]], $fontsarray[$rand_key[1]], "$cnum[1]");
imagettftext($image ,18 ,-3 ,37 ,30 ,$fontcolor[$rand_fontcolor[2]], $fontsarray[$rand_key[2]], "$cnum[2]");
imagettftext($image ,18 ,2 ,54 ,30 ,$fontcolor[$rand_fontcolor[3]], $fontsarray[$rand_key[3]], "$cnum[3]");
imagettftext($image ,18 ,-2 ,71 ,30 ,$fontcolor[$rand_fontcolor[4]], $fontsarray[$rand_key[4]], "$cnum[4]");
$digit = "$cnum[0]$cnum[1]$cnum[2]$cnum[3]$cnum[4]";
session_start();
$_SESSION['digit'] = $digit;
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>