Simple Image Verification to prevent spam on web forms
am 04.12.2007 07:13:16 von officexpboy"Simple Image Verification to prevent spam on web forms "
this code make sure that the one who
filling the form is human
Needed to enable GD support
============================================================ ======
form.php
session_start();
##########################################################
# Simple Image Verification to prevent spam on web forms #
# this code make sure that the one who #
# filling the form is human #
# Author - pradipsomani@gmail.com #
# Needed to enable GD support #
##########################################################
if (isset($_POST['submit'])){
if($_SESSION['string']==md5($_POST['pass']))
{
echo "correct code";
}
else
{
echo "incorrect code try again";
}
}
?>
============================================================ =======
assign.php
session_start();
#####################################################
# Image Verification to prevent spam - #
# this code make sure that the one who #
# filling the form is human #
# Author - pradipsomani@gmail.com #
# Needed to enable GD support #
#####################################################
function makerandom($minlength, $maxlength)
{
$characters = "0123456789abcXYZ"; // input string for image
characters
if ($minlength > $maxlength)
{
$length = mt_rand ($maxlength, $minlength);
}
else
{
$length = mt_rand ($minlength, $maxlength);
}
$totallen=strlen($characters)-1;
for ($i=0; $i<$length; $i++)
{
$result=$result.$characters[mt_rand(0,$totallen)];
}
return $result;
}
$getrand=makerandom(4,4); // length of your image characters
$_SESSION['string']=md5($getrand);
onrefresh($getrand);
function onrefresh($str)
{
$image=imagecreate(150,70);
// something to get a white background with black border
$back = imagecolorallocate($image, 0, 0, 0);
$border = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, 149,69, $border);
imagerectangle($image, 0, 0,149,69, $back);
$textcolor=imagecolorallocate($image,255,0,0);
//to write string in image
imagestring($image, 5, 40, 25, "$str", $textcolor);
header('Content-type:image/png');
imagepng($image);
}
?>