前言
验证码(CAPTCHA)是“Completely Automated Public Turing test to tell Computers and Humans Apart”(全自动区分计算机和人类的图灵测试)的缩写,是一种区分用户是计算机还是人的公共全自动程序。
前端代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
kg.captcha({
bind: "#captchaBox" ,
success: function (e) {
console.log(e);
},
failure: function (e) {
console.log(e);
},
refresh: function (e) {
console.log(e);
}
});
"captchaBox" >载入中 ...
|
PHP代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
include "public/KgCaptchaSDK.php" ;
$appId = "appId" ;
$appSecret = "appSecret" ;
$request = new kgCaptcha( $appId , $appSecret );
$request ->appCdn = "https://cdn.kgcaptcha.com" ;
$request ->token = $_POST [ "kgCaptchaToken" ];
$request ->userId = "kgCaptchaDemo" ;
$request ->connectTimeout = 10;
$requestResult = $request ->sendRequest();
if ( $requestResult ->code === 0) {
echo "验证通过" ;
} else {
echo "验证失败,错误代码:{$requestResult->code}, 错误信息:{$requestResult->msg}" ;
}
|
效果展示
相关链接
SDK开源地址:github.com/KgCaptcha,顺便做了一个演示:www.kgcaptcha.com/demo/
以上就是分享一个PHP免费验证码(附代码)的详细内容
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。