|
Posted by officexpboy on 12/04/07 06:13
"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
<?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";
}
}
?>
<html>
<body>
<form action="form.php" method="post" name="check">
<p>Email :
<input type="text" name="email">
</p>
<p><img src="assign.php"><br>
<br>
<input type="text" name="pass">
</p>
<p>
<input type="submit" name="submit" value="Check">
</p>
</form>
</body>
</html>
===================================================================
assign.php
<?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);
}
?>
Navigation:
[Reply to this message]
|