是否有可用于验证码的免费PHP库

q09*_*987 2 php captcha

在我们的网站上,我们采用reCAPTCHA来防止垃圾邮件.但是,我们的客户抱怨验证过于复杂.我也同意reCAPTCHA对于普通人来说太复杂了.对于不懂英语的人来说尤其困难.

我发现mail.yahoo.com的CAPTCHA功能是合理的,我不知道我是否可以像reCAPTCHA一样免费使用它.

谢谢

更新

我认为我最初的想法是找到一个可用于验证码的免费PHP库.我只需要一些简单的方法来进行验证码,而不是让我的客户觉得即使是真正的人类来解决这些问题也是如此困难.

Azm*_*sov 6

大多数主机允许PHP的GD图像处理.它实际上很容易学习,你可以在10或20分钟内制作自己的验证码.也就是说,如果您已经了解PHP.

这是一个非常简单的脚本示例:linky

例:

示例Captcha

码:

<?php
/*
Author: Simon Jarvis
Modified: Azmisov
Copyright: 2006 Simon Jarvis
License: GPL2
Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php
*/

//OPTIONS
$dwidth = 260;
$dheight = 90;
$dcharacters = 6;
//https://fontlibrary.org/en/font/jellee-typeface
$font = './jellee_roman.ttf';
$possible = '234679ABCDEHJLMNPTUVWXY';

//CODE
session_start();
function generateCode($characters) {
    global $possible;
    $code = '';
    $len = strlen($possible)-1;
    for($i=0; $i<$characters; $i++)
        $code .= substr($possible, mt_rand(0, $len), 1);
    return $code;
}
function createCaptcha($width,$height,$characters) {
    global $font;
    $code = generateCode($characters);
    $_SESSION['captcha'] = $code;
    //font size will be 75% of the image height
    $font_size = $height * 0.4;
    $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
    //set the colours
    $background_color = imagecolorallocate($image, 20, 58, 78);
    $text_color = imagecolorallocate($image, 74, 143, 200);
    $noise_color = imagecolorallocate($image, 100, 120, 200);
    //generate random dots in background
    for( $i=0; $i<($width*$height)/3; $i++)
        imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
    //generate random lines in background
    for($i=0; $i<($width*$height)/150; $i++)
        imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
    //create textbox and add text
    $textbox = imagettfbbox($font_size, 0, $font, $code) or die('Error in imagettfbbox function');
    $x = ($width - $textbox[4])/2;
    $y = ($height - $textbox[5])/2;
    imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code) or die('Error in imagettftext function');
    //generate random dots/lines in foreground
    for($i=0; $i<2; $i++)
        imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
    for( $i=0; $i<40; $i++)
        imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 3, 3, $noise_color);
    //Apply filters
    imagefilter($image, IMG_FILTER_CONTRAST, 1);
    imagefilter($image, IMG_FILTER_EMBOSS);
    imagefilter($image, IMG_FILTER_EDGEDETECT);
    imagefilter($image, IMG_FILTER_NEGATE);
    /* output captcha image to browser */
    header('Content-Type: image/jpeg');
    imagejpeg($image);
    imagedestroy($image);
} 
createCaptcha($width,$height,$characters); 
?>
Run Code Online (Sandbox Code Playgroud)