Captcha
1.0.0
与作曲家:
{
...
"require" : {
"gregwar/captcha" : " 1.* "
}
}
您可以使用CaptchaBuilder
创建验证码:
<?php
use Gregwar Captcha CaptchaBuilder ;
$ builder = new CaptchaBuilder ;
$ builder -> build ();
然后您可以将其保存到文件中:
<?php
$ builder -> save ( ' out.jpg ' );
或者直接输出:
<?php
header ( ' Content-type: image/jpeg ' );
$ builder -> output ();
或者直接将其内联到 HTML 页面中:
<img src=" <?php echo $ builder->inline(); ?> " />
您将能够获取代码并将其与用户输入进行比较:
<?php
// Example: storing the phrase in the session to test for the user
// input later
$ _SESSION [ ' phrase ' ] = $ builder -> getPhrase ();
您可以将该短语与用户输入进行比较:
if ( $ builder -> testPhrase ( $ userInput )) {
// instructions if user phrase is good
}
else {
// user phrase is wrong
}
您可以使用这些功能:
build()
之前调用ocrad
软件读取 OCR,则返回true
,您需要启用 shell_exec,安装 imagemagick 和 ocradocrad
无法读取为止如果您想更改字符数,可以使用额外参数直接调用短语构建器:
use Gregwar Captcha CaptchaBuilder ;
use Gregwar Captcha PhraseBuilder ;
// Will build phrases of 3 characters
$ phraseBuilder = new PhraseBuilder ( 4 );
// Will build phrases of 5 characters, only digits
$ phraseBuilder = new PhraseBuilder ( 5 , ' 0123456789 ' );
// Pass it as first argument of CaptchaBuilder, passing it the phrase
// builder
$ captcha = new CaptchaBuilder ( null , $ phraseBuilder );
您还可以直接将想要的短语传递给构建器:
// Building a Captcha with the "hello" phrase
$ captcha = new CaptchaBuilder ( ' hello ' );
如果您想查看示例,可以查看demo/form.php
,它使用demo/session.php
呈现验证码并在提交后检查它
您可以查看以下存储库以享受打包此验证码生成器的 Symfony 2 捆绑包:https://github.com/Gregwar/CaptchaBundle
您可以使用以下扩展与 Yii2 框架集成:https://github.com/juliardi/yii2-captcha
该库受 MIT 许可,请查看LICENSE
文件