Share a PHP free verification code (with code)

藏色散人
Release: 2023-04-23 17:34:02
forward
1801 people have browsed it

Preface

CAPTCHA is the abbreviation of "Completely Automated Public Turing test to tell Computers and Humans Apart", It is a public, fully automatic program that distinguishes whether the user is a computer or a human.

Share a PHP free verification code (with code)

Front-end code

<script src="captcha.js?appid=xxx"></script>

<script>
kg.captcha({
    // 绑定元素,验证框显示区域
    bind: "#captchaBox",

    // 验证成功事务处理
    success: function(e) {
        console.log(e);
    },

    // 验证失败事务处理
    failure: function(e) {
        console.log(e);
    },

    // 点击刷新按钮时触发
    refresh: function(e) {
        console.log(e);
    }
});
</script>

<div id="captchaBox">载入中 ...</div>
Copy after login

PHP code

<?php
include "public/KgCaptchaSDK.php";

// 填写你的 AppId,在应用管理中获取
$appId = "appId";

// 填写你的 AppSecret,在应用管理中获取
$appSecret = "appSecret";

$request = new kgCaptcha($appId, $appSecret);
// 填写应用服务域名,在应用管理中获取
$request->appCdn = "https://cdn.kgcaptcha.com";

// 前端验证成功后颁发的 token,有效期为两分钟
$request->token = $_POST["kgCaptchaToken"];

// 当安全策略中的防控等级为3时必须填写
$request->userId = "kgCaptchaDemo";

// 请求超时时间,秒
$request->connectTimeout = 10;

$requestResult = $request->sendRequest();
if ($requestResult->code === 0) {
    // 验签成功逻辑处理
    echo "验证通过";
} else {
    // 验签失败逻辑处理
    echo "验证失败,错误代码:{$requestResult->code}, 错误信息:{$requestResult->msg}";
}
Copy after login

Effect display

Related links

SDK open source address: github.com/KgCaptcha, by the way A demonstration: www.kgcaptcha.com/demo/

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Share a PHP free verification code (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!