mr_mind Posted January 9, 2008 Share Posted January 9, 2008 I was told to post this here. Alright i was searching for captcha a while back and i found one that worked, though after a while it was giving me lots and lots of problems, So i have come up with my own and would like to beta test it on you guys. The hardest part was making a random string generator, because it was so hard i have made it a lot bigger to use it later on in my site. here is the random string script: <?php function str_rand($string_length, $string_type='numeric') { $string_array = array('numeric','alpha','alnum','alnum_cap','alnum_low','alpha_cap','alpha_low'); if(array_search($string_type, $string_array) !== FALSE) { if($string_length < 40) { switch($string_type) { case 'numeric': $string_seed = range('1','9'); break; case 'alpha': $string_seed = array_merge(range('A','Z'), range('a','z')); break; case 'alpha_cap': $string_seed = range('A','Z'); break; case 'alpha_low': $string_seed = range('a','z'); break; case 'alnum': $string_seed = array_merge(range('1','9'), array_merge(range('A','Z'), range('a','z'))); break; case 'alnum_cap': $string_seed = array_merge(range('1','9'), range('A','Z')); break; case 'alnum_low': $string_seed = array_merge(range('1','9'), range('a','z')); break; } $string_random = ''; for($i=0;$i<$string_length;$i++) { $string_key = array_rand($string_seed, 1); $string_random .= $string_seed[$string_key]; } return $string_random; } else { return 'Invalid string length'; } } else { return 'Invalid string type'; } } ?> Now we have the image generating function <?php require_once "/var/www/localhost/htdocs/inc/functions.php"; $image_width = 270; $image_height = 40; $image_base = imagecreatetruecolor($image_width,$image_height); $image_background = imagecolorallocate($image_base, 250, 250, 250); imagefill($image_base, 0, 0, $image_background); if(isset($_GET['s'])) { $image_text = $_GET['s']; } else { $image_text = str_rand(6, 'alnum'); } $image_text_array = str_split($image_text, 1); $image_text_color = imagecolorallocate($image_base,0,0,0); $image_font = '/var/www/localhost/htdocs/fonts/verdana.ttf'; $image_letter = ($image_width/8); header('Content-type: image/png'); for($i=0;$i<=16;$i++) { $image_line_color = imagecolorallocatealpha($image_base,mt_rand('0','200'),mt_rand('0','200'),mt_rand('0','200'),mt_rand('20','115')); imagesetthickness($image_base,mt_rand('1','3')); imageline($image_base,mt_rand('0',$image_width),mt_rand('0',$image_height),mt_rand('0',$image_width),mt_rand('0',$image_height),$image_line_color); } $image_dots_spacing = 10; $image_dots_y = $image_height/$image_dots_spacing; for($i=0;$i<=$image_dots_y;$i++) { $image_line_color = imagecolorallocatealpha($image_base,mt_rand('0','200'),mt_rand('0','200'),mt_rand('0','200'),mt_rand('20','115')); imagesetthickness($image_base,2); } for($i=0;$i<=6;$i++) { $image_text_direction = mt_rand('1','2'); if($image_text_direction == 1) { imagettftext($image_base, 20,-mt_rand('5','15'),$image_letter,30,$image_text_color,$image_font,$image_text_array[$i]); } else { imagettftext($image_base, 20,mt_rand('5','15'),$image_letter,30,$image_text_color,$image_font,$image_text_array[$i]); } $image_letter = $image_letter+($image_width/8); } imagepng($image_base); imagedestroy($image_base); ?> Then we have the verification that the image is correct <?php function captcha_check($response, $captcha) { $captch_check = @substr_compare($captcha, $response, 0, strlen($captcha), TRUE); if($captch_check == 0) { return '1'; } else { return '2'; } } ?> There you go, tell me your opinions. Quote Link to comment https://forums.phpfreaks.com/topic/85135-image-verification/ Share on other sites More sharing options...
ober Posted January 10, 2008 Share Posted January 10, 2008 Who told you to post it on this board? Critiques are for looks and functionality, not reviewing code. I'd move the thread now but I want to know who told you to put it here first to make sure I'm not stepping on another mod/admin. Quote Link to comment https://forums.phpfreaks.com/topic/85135-image-verification/#findComment-435203 Share on other sites More sharing options...
mr_mind Posted January 10, 2008 Author Share Posted January 10, 2008 http://www.phpfreaks.com/forums/index.php?action=profile;u=48068 Quote Link to comment https://forums.phpfreaks.com/topic/85135-image-verification/#findComment-435288 Share on other sites More sharing options...
ober Posted January 11, 2008 Share Posted January 11, 2008 ok then... moving. Quote Link to comment https://forums.phpfreaks.com/topic/85135-image-verification/#findComment-436147 Share on other sites More sharing options...
Coreye Posted January 11, 2008 Share Posted January 11, 2008 "If you want us to rate the script then you should post it on the critique forum." is what I said. You were not looking for help on the actual script and were looking for someone to to test your code. The beta test board is the correct board for that, I just didn't know what you were wanting because all you did was show the code. Quote Link to comment https://forums.phpfreaks.com/topic/85135-image-verification/#findComment-436150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.