/ Published in: PHP
Save this snippet as .php file and use it as image source. This captcha code shows random arithmetic's questions. You can download needed font from http://www.1001fonts.com/fontdetails.html?fontid=2939
Expand |
Embed | Plain Text
$width = 120; $height = 30; $im = @imagecreate($width, $height) imagecolorallocate($im, 247, 250, 233); $noise_color = imagecolorallocate($im, 253, 175, 90); for( $i=0; $i<($width*$height)/3; $i++ ) { } /* generate random lines in background */ for( $i=0; $i<($width*$height)/120; $i++ ) { } $text_color = imagecolorallocate($im, 175, 102, 43); if($action[0] == '+') { $_SESSION['code'] = $a + $b; } elseif($action[0] == '*') { $_SESSION['code'] = $a * $b; } elseif($action[0] == '-') { $c = $b+1; $_SESSION['code'] = $a - $b; } $text = $a.$action[0].$b; imagettftext($im, 18, $angle, 29+($j*23), (18+(($height-18)/2)), $text_color, './WC_Wunderbach_Rough.ttf', $text[$j] ); } imagepng($im); imagedestroy($im); //usage : save this snippet as captcha.php file and use it that //point it as image source //<img src="captcha.php" /> //to check is it passed correctly, do following //if(isset($_SESSION['code']) && ($_POST['captcha'] == $_SESSION['code'])) //its needed to check is $_SESSION['code'] is set, because if somebody block //the image loading, the check ($_POST['captcha'] == $_SESSION['code']) will //return false positive if the form is sent with empty captcha field
You need to login to post a comment.
