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
文件