Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a free PHP library that can be used for captcha

Tags:

php

captcha

In the our website, we adopt reCAPTCHA to prevent spam. However, our clients complain that the validation is too complicated. I also agree that the reCAPTCHA is way too complicated for a regular person to read. It is especially hard for people who don't know English.

I found that the CAPTCHA function of mail.yahoo.com is reasonable and I don't know whether or not I can use it for free like reCAPTCHA.

Thank you

Update

I think my original idea is to find a free PHP library that can be used for captcha. I just need some simple way to do the captcha rather than make my clients feel it is so difficult even for a real human to solve the words.

like image 949
q0987 Avatar asked Sep 06 '25 17:09

q0987


2 Answers

Most hosts allow GD image manipulation for PHP. Its actually really easy to learn, and you could make your own captcha script in 10 or 20 minutes. That is, if you already know PHP.

This is a pretty simple script example: linky

Example:

Example Captcha

Code:

<?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); 
?>
like image 148
Azmisov Avatar answered Sep 09 '25 12:09

Azmisov


I'd recommend one more place: phpclasses.org, in this site, you can find all sort of PHP resources. I had to use a captcha and found it there. I downloaded it, but lost the link tough, sorry :(

Anyways, looking for a captcha class there won't take more than 5 minutes.

Try this url

Best regards, David!

like image 37
David Conde Avatar answered Sep 09 '25 14:09

David Conde