首页 > 其他 > 详细

Helpers\RainCaptcha

时间:2016-07-05 13:57:15      阅读:220      评论:0      收藏:0      [点我收藏+]

Helpers\RainCaptcha

This class can validate CAPTCHA images with RainCaptcha.

It can generate an URL to display a CAPTCHA validation image served by the RainCaptcha service.

The class can also send a request to RainCaptcha API to verify if the text that the user entered matches the text in the CAPTCHA image.

RainCaptcha is a CAPTCHA class that does not require any image processing extensions (GD, ImageMagick, etc). CAPTCHA was developed to be readable by humans and resistant to OCR software. It generates black-and-white images with 5 distorted letters on them and noise. Its checking algorithm is case-insensitive.

Create an alias:

use Helpers\RainCaptcha;

To use the class create a new instance, this can then be used to generate a captcha image using ->getImage().

$rainCaptcha = new RainCaptcha();

<img id="captchaImage" src="<?php echo $rainCaptcha->getImage(); ?>" />

<input name="captcha" type="text" />

<button type="button" class=‘btn btn-danger‘ onclick="document.getElementById(‘captchaImage‘).src = 

‘<?php echo $rainCaptcha->getImage(); ?>&morerandom=‘ + Math.floor(Math.random() * 10000);"><span class="icon icon-refresh"></span></button>

To check if a user‘s input matches the captcha

$rainCaptcha = new RainCaptcha();

if (!$rainCaptcha->checkAnswer($_POST[‘captcha‘])) {
    die(‘You have not passed the CAPTCHA test!‘);
}

Helpers\RainCaptcha

原文:http://www.cnblogs.com/chunguang/p/5643192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!