


Laravel integrates Geetest verification code method php example
This article mainly introduces the method of integrating Geetest verification code with Laravel. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.
Geetest integration process
-
The general logic of realizing login
Register a JiExperience account
Register a behavioral verification in the background management of “JiExperience”
Configure our controller and routing according to the official Demo
Configure our login template according to the official Demo
Test
Geetest integration detailed process
1. Implement the general logic of login
Create the controller php artisan make:controller GeetestController
Edit Controller/app/Http/Controllers/GeetestController
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
The view is a simple form, omitted .
2. Omit => "Register"
3. Omit => "Backend login" => "Behavior verification" => Apply for an id & key
4. Configure the controller and routing
First of all, the core class library provided by the Demo is a class file called class.geetestlib.php, and the class name is GeetestLib. We create a controller with the same class name to replace it php artisan make:controller GeetestLib
Don’t copy the class, just copy the content in the class
GeetestController control Device implementation logic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
Configuration routing/routes/web.php
1 2 3 4 |
|
5. Improve the login template/resources/views/Geetest/login.blade.php
Need to import jquery (we use npm run dev compiled app.js to integrate jquery)
Need to import Demo to give gt.js, we put it under public/js<script src="/js/gt.js"></script>
In fact, in theory, it can also be placed under /resouces/assets/js/, and require in /resouces/assets/js/app.js to let it participate in being compiled, and package it directly in public/js The integration takes effect.
On the template, two style classes need to be defined.show & .hide => The styles used for gt.js control prompt information can also be written under /resouces/assets/sass/
Submit an id to the "Login" button in the form
Copy the front-end logic js provided in the Demo, pay attention to binding this button
Pay attention to the .ajax configuration The url must be the path we defined in web.php with 'GeetestStartCaptchaServlet'
Specific code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
Test Success
Things that can be optimized
It is best not to use a "controller" as the core class library. GeetestLib should be integrated into another place
The js & css on the view template should be written in resources/assets to participate in the compilation of generating app.css & app.js
We have not written the specific login logic. You should also be able to confirm whether the Geetest verification is successful in the login verification check() method. You can refer to Demo
. The above is the entire content of this article. I hope it will be helpful to everyone's study. I also hope that everyone will learn more. Support PHP Chinese website.
Articles you may be interested in:
Phpstorm Xdebug breakpoint debugging method for PHP php instance
php strftime function gets the date and time php basics
Sample code for PHP multi-dimensional array to specify multi-field sorting_php example
The above is the detailed content of Laravel integrates Geetest verification code method php example. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement the table function of custom click to add data in dcatadmin (laravel-admin) When using dcat...

Method for obtaining the return code when Laravel email sending fails. When using Laravel to develop applications, you often encounter situations where you need to send verification codes. And in reality...

The impact of sharing of Redis connections in Laravel framework and select methods When using Laravel framework and Redis, developers may encounter a problem: through configuration...

Custom tenant database connection in Laravel multi-tenant extension package stancl/tenancy When building multi-tenant applications using Laravel multi-tenant extension package stancl/tenancy,...

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

How to check the validity of Redis connections in Laravel6 projects is a common problem, especially when projects rely on Redis for business processing. The following is...

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

A problem of duplicate class definition during Laravel database migration occurs. When using the Laravel framework for database migration, developers may encounter "classes have been used...
