0% found this document useful (0 votes)
534 views4 pages

Geetest Installation

The document provides steps and code samples for integrating Geetest captcha into a PHP application. It includes downloading the SDK, defining variables, making API calls to get a challenge string and validate the captcha response, and initializing the captcha widget in the front-end JavaScript. The SDK provides methods to get a challenge from the Geetest API and validate the captcha server-side after user interaction.

Uploaded by

Narutõ Uzumakii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
534 views4 pages

Geetest Installation

The document provides steps and code samples for integrating Geetest captcha into a PHP application. It includes downloading the SDK, defining variables, making API calls to get a challenge string and validate the captcha response, and initializing the captcha widget in the front-end JavaScript. The SDK provides methods to get a challenge from the Geetest API and validate the captcha server-side after user interaction.

Uploaded by

Narutõ Uzumakii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

5 steps to integrate geetest captcha

1. your front-end interacts with your backend to get challenge string


2. your front-end initializes geetest captcha
3. user slides the captcha image and get validate result
4. your front-end interacts with your backend to perform server-side validation
5. your front-end handles success or failure validation cases

PHP

Download SDK

1 git clone https://github.com/GeeTeam/gt3-php-sdk.git


2
3 or
4
5 https://github.com/GeeTeam/gt3-php-sdk/archive/master.zip

SDK provides two useful methods

1 # this method requests geetest api to get challenge string to respond to


front-end
2 # so front-end can initialize captcha
3 public function pre_process($param, $new_captcha=1) {
4 }
5
6 # after user slides the captcha image, front-end should request server-
side validation with $challenge, $validate, $seccode
7 # this method validates captcha and return 1 or 0
8 public function success_validate($challenge, $validate, $seccode,$param,
$json_format=1) {
9 }

Dene variables to use the SDK

1 define("CAPTCHA_ID", "$YOUR_CAPTCHA_ID");
2 define("PRIVATE_KEY", "$YOUR_PRIVATE_KEY");

Front-end

Include SDK
1 <script src="http://static.geetest.com/static/tools/gt.js"></script>
2
3
4 # or download the js to your own server and include it like this
5 <script src="gt.js"></script>

How to use
1 ajax('/$YOUR_PRE_PROCESS_API_ENDPOINT', null, function(data) {
2 initGeetest({
3 gt: data.gt,
4 challenge: data.challenge,
5 offline: !data.success,
6 new_captcha: data.new_captcha
7 }, function (captchaObj) {
8 # your operation to add captchaObj to the DOM tree
9 captchaObj.appendTo('#captcha-box');
10
11 # captcha is ready
12 captchaObj.onReady(function() {
13
14 });
15
16 # user slides the captcha image and successfully verified in front-
end
17 # request server-side validation here
18 captchaObj.onSuccess(function() {
19 var result = captchaObj.getValidate();
20
21 ajax('/$YOUR_SERVER_SIDE_VALIDATION_API_ENDPOINT', {
22 geetest_challenge: result.geetest_challenge,
23 geetest_validate: result.geetest_validate,
24 geetest_seccode: result.geetest_seccode,
25 }, function (data) {
26 # check if server-side validated successfully with data
response
27 # this is up to your implementation
28 # e.g.
29 # success -> reward user with bitcoin
30 # failure -> inform user with error message
31 });
32 });
33
34 # something is wrong, handle it here
35 captchaObj.onError(function() {
36 });
37
38 # captcha is closed
39 captchaObj.onClose(function() {
40 });
41 })
42 });

verbose conguration parameters for initGeetest method


parameter type meaning required

gt string captcha id yes

challenge string challenge string for each captcha yes

oine boolean indicates if geetest server is down yes

new_captcha boolean indicates if you are using geetest 3.0 yes

width string widht of button, default 300px no

style of captcha, can be [oat, popup, custom,


product string no
bind], default is popup

lang string language, can be [zh-cn, en], default is zh-cn no

validation request timeout in millionseconds,


timeout number no
default 30000

You might also like