here is a captcha code which i have developed for wap sites.
1. create a new file image.php and put the next code code to it:
create folder gumcha where the captcha image script is and chmod 777 it.
and then use this peace of code which will check if the gumcha generated code is correct:
1. create a new file image.php and put the next code code to it:
PHP Code:
<?php
@exec("find ./gumcha/ -maxdepth 1 -type f -mtime +1 -exec rm -f {} \;");
$code = rand_string(5);
file_put_contents('./gumcha/'.$code, $code);
function rand_string( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyz123456789";
$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return $str;
}
/* YOU CAN MODIFY THE IMAGE CODE FROM HERE TO CREATE MORE COOL CAPTCHA IMAGES, eg. with different backgrounds */
header("Content-type: image/gif");
$im = @imagecreate(60, 25)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 3, 5, 5, $code, $text_color);
imagegif($im);
imagedestroy($im);
?>
and then use this peace of code which will check if the gumcha generated code is correct:
PHP Code:
if($_POST){
$gumcha_code = $_POST['code'];
if(gumcha_check($gumcha_code) == true)
{
// HERE GOES THE CONTENT AFTER THE CAPTCHA VALIDATION
}else echo 'WRONG CAPTCHA CODE';
}
function gumcha_check($code)
{
$code = trim($code);
$code = str_replace('.','',$code);
$code = strtolower($code);
if (preg_match("/[^\da-z]+/", $code)) return false;
elseif(strlen($code)<2)return false;
elseif(file_exists('./gumcha/'.$code))
{
@unlink('./gumcha/'.$code);
return true;
}
else return false;
}
Comment