In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how PHP implements extreme CAPTCHA. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Paste a few URLs that you might be able to use:
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 of all, make sure that the front end uses the page, such as the landing page
1. Visit the login page to introduce the class library:
If your website uses https, you only need to replace the introduction of the extreme library with the https protocol, and you don't need to change it anywhere else. For example, you can replace it with the following code:
two。 Initialize the front end
The following code needs to be executed after the page is loaded. 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 (), / / add random numbers to prevent caching type: "get", dataType: "json", success: function (data) {/ / use initGeetest interface / / Parameter 1: configure Parameter / / Parameter 2: callback The first parameter CAPTCHA object of the callback, which can then be used to do events such as appendTo initGeetest ({gt: data.gt, challenge: data.challenge, product: "popup", / / product form, including: float,embed,popup. Note that offline:! data.success / / is only valid for the PC verification code. It means that the user detects whether the extreme server is down in the background. With SDK, users generally do not need to pay attention to}, handlerPopup);})
The above code means that after the page is loaded, you need to go to the URL address you specify to get the CAPTCHA information. As for what is written in the above URL address ".. / web/StartCaptchaServlet.php", we will explain in detail in the server-side code deployment.
But it is important to note that in the above code, there is a callback function called "handlerPopup", which is the real initialization code for the verification code you need:
/ / the code details var handlerPopup = function (captchaObj) {/ / register the submit button event, such as the login button $("# popup-submit") .click (function () {/ / omitted here in the login screen, some steps to obtain login data / / first verify whether the verification code var validate = captchaObj.getValidate () is clicked If (! validate) {alert ('Please complete the verification first') ; return } / / submit CAPTCHA information, such as login page, you need to submit login information, username and password and other login data $.ajax ({url: ".. / web/VerifyLoginServlet.php", type: "post", / / dataType: "json", data: {/ / username and password and other data, etc.) Do not demonstrate username:username, password:password, / / CAPTCHA data, you do not need to obtain these data by yourself / / these are the three values required for secondary verification / / of course, you can also directly set the CAPTCHA to verify separately. Omit other information geetest_challenge: validate.geetest_challenge, geetest_validate: validate.geetest_validate, geetest_seccode: validate.geetest_seccode}, / / here is the handler that correctly returns the processing result / / suppose you return 1mem2mag3 / / of course Normally, JSON data success: function (result) {/ / 1 indicates verification failed if (result = = "1") {alert ("verification failed!") ;} else if (result = = "2") {alert ("wrong username or password!") ;} else if (result = = "3") {alert ("login succeeded!") ; / / after logging in successfully, you can do other processing here} else {alert ("login error!") / / the pop-up needs to bind the trigger CAPTCHA pop-up button / / for example, on the login page, the trigger button is the login button captchaObj.bindOn ("# popup-submit"); / / add the CAPTCHA to the element whose id is captcha / / the CAPTCHA will display captchaObj.appendTo ("# popup-captcha") in the element specified below / / for more APIs, please see http://www.geetest.com/install/sections/idx-client-sdk.html};
At this point, all the settings of the front end have been written, and 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 like ".. / web/StartCaptchaServlet.php". What should we write in this address:
How to get authentication ID and authentication Key:
1. Register an account from the verification backend
two。 Add validation to get a set of ID/Key for current verification
3. Replace ID and Key with the value of the captcha_id/private_key variable in the config.php file, respectively
4. Server verification after clicking the submit button (secondary verification)
For example, when the user logs in, you submit the user name, password and CAPTCHA information to the server. At this time, you can do verification:
Thank you for reading! This is the end of this article on "how to achieve extreme verification code in PHP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.