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

时间:2010-09-03 16:21:00

标签: php captcha

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

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

谢谢

更新

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

5 个答案:

答案 0 :(得分:6)

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

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

示例:

Example 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); 
?>

答案 1 :(得分:3)

我建议再增加一个地方:phpclasses.org,在这个网站上,你可以找到所有类型的PHP资源。我不得不使用验证码并在那里找到它。我下载了它,但遗失了链接,抱歉:(

无论如何,寻找验证码课程的时间不会超过5分钟。

尝试this url

祝你好运, 大卫!

答案 2 :(得分:1)

我构建了一个基于GD的简单验证码。如果图像对用户来说很难,它甚至还有数学模式。

http://github.com/Xeoncross/micromvc/blob/v2.0.0/modules/core/classes/captcha.php

答案 3 :(得分:1)

我不确定是否还有任何课程,但是你可以保留一系列反机器人问题,例如“火热还是冷?”而不是CAPTCHA。并使用那些而不是图像。这种方法在网络应用程序中越来越受欢迎。

编辑:像这样! http://textcaptcha.com/

答案 4 :(得分:1)

Microsoft's ASIRRA,它只是猫和狗的照片,你必须选择所有的猫。

相关问题