You can find this article, stating that you are not completely unfamiliar with the verification of the test, all the nonsense I will not say, and directly began to say how to use it, but before this, paste a few you may be able to get the URL:
Official website: http://www.geetest.com/
Official Document: Http://www.geetest.com/install/sections/idx-basic-introduction.html
Github:https://github.com/geeteam/gt-php-sdk.git
How to use:
First, confirm the front-end use of 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 the Introduction class library on the landing page:
If your site uses HTTPS, you only need to change the place where you introduced the vault to the HTTPS protocol, and you don't need to make 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. Initializing the front end
The following code needs to be executed after the page is loaded, and if you use jquery, you can write it in $ (function () {});
$.ajax ({ //Get id,challenge,success (whether failback is enabled) 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: Configuration parameters //Parameter 2: Callback, Callback's first parameter Authenticode object, which can then be used to do events such as Appendto initgeetest ({ gt:data.gt, challenge:data.challenge, product : "Popup",//Products form, including: float,embed, Popup Note Only for the PC version of the verification code valid offline:!data.success//indicates that the user background detection of the server is down, with the SDK, the user generally do not need to pay attention to }, Handlerpopup);} );
The above code means that after the page is loaded, it needs to get the CAPTCHA information to the URL address you specified, as to the URL address above. /web/startcaptchaservlet.php "What is written inside, this we will explain in detail in the server-side code deployment.
However, it is necessary to note that the above code has a callback function called "Handlerpopup", this function is the real initialization code you need to verify code: The following:
The code details var handlerpopup = function (captchaobj) {//Register submit button event, such as login button on landing page $ ("#popup-submit"). Click (function () {/ /omitted here in the login interface, get the login data of some steps//first check whether the verification code is clicked 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, user name and password login data $.ajax ({URL: "). /web/verifyloginservlet.php ", type:" POST ",//DataType:" JSON ", data: {//user name and password, etc., get it yourself, don't do a demo Username:username, Password:password,///CAPTCHA data, these data are not obtained by themselves//This is the three values required for two validations//Of course, you can also directly set up a test Separate verification of the code, omit other information geetest_challenge:validate.geetest_challenge, Geetest_validate:validate.geetest_validate, Geetest_seccode:validate.geetest_seccode},//This is the handler function that correctly returns the result of the processing//assuming that you have returned to the----and of course, the normal situation is to return JSO n Data success:function (Result) {///1 indicates that the verification code failed if (result = = "1") {alert ("Captcha validation failed!") "); }else if (result = = "2") {alert ("User name orWrong password! "); }else if (result = = "3") {Alert ("Login succeeded!") "); Landed successfully, can be done here other processing}else{alert ("Login Error!") "); } } }); }); Pop-up need to bind trigger code popup button//For example, on the landing page, this trigger button is the login button Captchaobj.bindon ("#popup-submit"); Add the verification code to the element with ID CAPTCHA//The verification code will be displayed in the element specified below Captchaobj.appendto ("#popup-captcha"); More interface references: http://www.geetest.com/install/sections/idx-client-sdk.html};
At this point, all the settings on the front end are written, the 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 such as ". /web/startcaptchaservlet.php, what does it say in this address:
<?php//introduces the file require_once dirname (dirname (__file__)). '/lib/class.geetestlib.php '; require_once dirname (DirName (__file__)). '/config/config.php ';//instantiation, instantiated parameters are configured in config, respectively: Verify ID and verify key, how to obtain the following will say. $GTSDK = new Geetestlib (captcha_id, Private_key); session_start ();//This is the identity of the user, or the identity of the server, if your project is not pre-set, Can be set as follows: if (!isset ($_session[' user_id ')) { $_session[' user_id ']=uniqid ();//generate a unique ID} $user _id = $_session[' user_id '];//or, you write directly://$user _id = "Test"; Generate the CAPTCHA information and return 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 verification ID and verify key:
1. Register your account from the verification background
2. Add validation to get a set of currently validated Id/key
3. Replace the ID and key with the value of the Captcha_id/private_key variable in the config.php file, respectively
4. Click on the service-side check after the Submit button (two verification)
As mentioned above, when the user logs in, you put the user name and password and verification code information to the server, this time, you can do the verification:
<?php//introduces the 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 verification code to verify the identity of the passed $code_flag=false; Here to get the user_id you set previously, send to the verification server to do the check $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) { //Verification code verified successfully $code _flag=true; }} else{ if ($GtSdk->fail_validate ($_post[' geetest_challenge '],$_post[' geetest_validate '],$_post[' geetest_ Seccode ']) { //Verification Code verification successful $code _flag=true; }} If the verification code succeeds, then other check if ($code _flag) { //other validation actions// user name is incorrect, return 2, other error returned 3, etc... }else{ //Verification code verification failed, return 1, here and above to echo, 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 the support of this site!