You can find this article, you are not completely unfamiliar with the verification of the test, all the nonsense I will not say, directly start the table to say how to use it, but before that, paste a few you may use the URL:
Official website: http://www.geetest.com/
Official documents: http://www.geetest.com/install/sections/idx-basic-introduction.html
Github:https://github.com/geeteam/gt-php-sdk.git
How to use:
First make sure the front end uses the page, such as landing page
<script src= "Http://code.jquery.com/jquery-1.12.3.min.js" ></script>
<script src= "Http://static.geetest.com/static/tools/gt.js" ></script>
1. Access to the login page to introduce the class library:
If your site uses HTTPS, you will only need to change to the HTTPS protocol where you introduced the database, and you do not need to make any changes elsewhere. For example, replace the following code:
<script src= "Https://code.jquery.com/jquery-1.12.3.min.js" ></script>
<script src= "Https://static.geetest.com/static/tools/gt.js" ></script>
2. Initialize Front end
The following code needs to be executed after the page is loaded, if you use jquery, you can write in $ (function () {});
$.ajax ({
//Get Id,challenge,success (failback)
URL: ".. /web/startcaptchaservlet.php?t= "+ (new Date ()). GetTime (),//plus random number to prevent cache
type:" Get ",
DataType:" JSON ",
Success:function (data) {
//using Initgeetest interface
//parameter 1: Config parameter
//Parameter 2: Callback, callback's first parameter verification code object, then you can use it to do events like Appendto
initgeetest ({
gt:data.gt,
challenge:data.challenge, product
: "Popup",//Products form, including: float,embed, Popup Note that only the PC version of the validation code effective
offline:!data.success///indicates that the user background detection of the server is not downtime, with the SDK, users generally do not need to pay attention to
}, Handlerpopup);
}
;
The above code means that after the page is loaded, you need to obtain the authentication code information on the URL address you specify, as to the URL above. /web/startcaptchaservlet.php "What is written inside, this we will specify in the server-side code deployment."
But what you need to note is that there is a callback function called "Handlerpopup" in the code above, which is the real initialization code that you need to verify the code: the following:
The code details the var handlerpopup = function (captchaobj) {//Register the Submit button event, such as the login button on the landing page $ ("#popup-submit"). Click (function () {
Here omitted in the login interface, get the login data some steps//first check whether click the verification code var validate = Captchaobj.getvalidate (); if (!validate) {alert (' please complete verification first!
');
Return //Submit Verification code information, such as landing page, you need to submit login information, username and password login data $.ajax ({URL: "...) /web/verifyloginservlet.php ", type:" POST ",//DataType:" JSON ", data: {//username and password, etc, get it yourself, don't do it. Username:username, Password:password,//Verification code data, these data do not have to obtain//This is the two times required to verify the three values//and of course, You can also set the verification code to separate check, omit other information geetest_challenge:validate.geetest_challenge, geetest_validate:validate.geetest_v
Alidate, Geetest_seccode:validate.geetest_seccode},//Here is the handler function to return the processing result correctly//Suppose you return to 1,2,3 Of course, the normal situation is to return the JSON data success:function (Result) {//1 indicates that the validation code validation failed if (result = = "1") {alert ( "Validation code verification failed!"
"); }else if (reSult = = "2") {alert ("User name or password is wrong!")
"); }else if (result = = "3") {Alert ("Login succeeded!")
"); The landing was successful and can be done here with other processing}else{alert ("Landing Error!").
");
}
}
});
});
Pop-up needs to bind trigger verification Code pop-up button//For example, in the landing page, the trigger button is the landing button Captchaobj.bindon ("#popup-submit");
Add the captcha to the element with ID CAPTCHA//The CAPTCHA will be displayed in the element specified below Captchaobj.appendto ("#popup-captcha");
More interface reference: http://www.geetest.com/install/sections/idx-client-sdk.html};
So far, all the settings on the front end have been written, official documentation: http://www.geetest.com/install/sections/idx-client-sdk.html
3. Server-side deployment (PHP)
In the first step, we set up an address like "... /web/startcaptchaservlet.php, "What do you write in this address:
<?php
//Introduce file
require_once dirname (dirname (__file__)). '/lib/class.geetestlib.php ';
Require_once dirname (dirname (__file__)). '/config/config.php ';
instantiated, the instantiated parameters are configured in config, respectively: Verify ID and verify key, and how to obtain the following.
$GtSdk = new Geetestlib (captcha_id, private_key);
Session_Start ();
This is the identity of the user, or the identification of the distinguished server, if your project is not pre-set, you can set it as follows: if
(!isset ($_session[' user_id ')) {
$_session[' user_ Id ']=uniqid ()//generate a unique ID
}
$user _id = $_session[' user_id '];
Alternatively, you write directly:
//$user _id = "Test";
Generates the CAPTCHA information and returns it to the client
$status = $GtSdk->pre_process ($user _id);
$_session[' gtserver ' = $status;
$_session[' user_id ' = $user _id;
echo $GTSDK->get_response_str ();
? >
How to obtain the validation ID and verify key:
1. From the verification background registration account
2. Add validation to get a set of currently validated Id/key
3. Replace the ID and key to the value of the Captcha_id/private_key variable in the config.php file
4. Click on the Submit button after the service-side checksum (two times verification)
For example, said above, the user login, you put the user name and password and authentication code information are submitted to the server, this time, you can do a check:
<?php
//Introduce file
require_once dirname (dirname (__file__)). '/lib/class.geetestlib.php ';
Require_once dirname (dirname (__file__)). '/config/config.php ';
Session_Start ();
$GTSDK = new Geetestlib (captcha_id, private_key);
For example, you set a validation code to verify the passing of the logo
$code _flag=false;
Here gets the user_id that you set up before, transmits to the extremely test server to do the verification
$user _id = $_session[' user_id '];
if ($_session[' gtserver '] = = 1) {
$result = $GtSdk->success_validate ($_post[' Geetest_challenge '), $_post[' Geetest_validate '], $_post[' Geetest_seccode ', $user _id);
if ($result) {
//Validate code validation successfully
$code _flag=true
}
} else{
if ($GtSdk->fail_validate $_post[' geetest_challenge '],$_post[' geetest_validate '],$_post[geetest_ ' Seccode ']) {
//validation code validation succeeded
$code _flag=true
}
}
If the verification code is successful, then another check
if ($code _flag) {
//other authentication operation//
user name is not correct, return 2, other error return 3, etc. .....
}else{
//Verification Code validation failed, return 1, here and above echoes, of course, my project did not simply return 1, but returned the JSON data
Echo 1;
Exit ( -1);
}
? >
Thank you for your reading, hope to help everyone, thank you for your support to this site!