• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Geetest Package for Laravel5

Laravel Geetest

Build Status DUB Support Release

Laravel Geetest is a package for Laravel 5 developed by Germey. It provides simple usage for laravel of Geetest.

Geetest Demo: Geetest

Installation

Laravel 5.0 or later is required.

This Package now supports Geetest 3.0.

For Geetest 2.0, please see LaravelGeetest 2.0

To get the latest version of Laravel Geetest, simply require the project using Composer:

$ composer require germey/geetest

Or you can add following to require key in composer.json:

"germey/geetest": "~3.0"

then run:

$ composer update

Next, You should need to register the service provider. Open up config/app.php and add following into the providers key:

Germey\Geetest\GeetestServiceProvider::class

And you can register the Geetest Facade in the aliases of config/app.php :

'Geetest' => Germey\Geetest\Geetest::class

Configuration

To get started, you need to publish vendor assets using the following command:

$ php artisan vendor:publish --tag=geetest

This will create a config file named config/geetest.php which you can configure geetest as you like.

It will also generate a views folder named resources/views/vendor/geetest, there will be a view file named geetest.blade.php. Here you can configure styles of geetest. For example, you can change the script alert() as you like.

Usage

Firstly, You need to register in Geetest. Creating an app and get ID and KEY.

For example. You can see app ID and KEY after you added an app in Geetest Admin Page

Then configure them in your .env file because you'd better not make them public.

Add them to .env as follows:

GEETEST_ID=0f1097bef7xxxxxx9afdeced970c63e4
GEETEST_KEY=c070f0628xxxxxxe68e138b55c56fb3b

Then, You can use render() in views like following, It will render a geetest code captcha:

{!! Geetest::render() !!}

For example, you can use it in form like this:

<form action="/" method="post">
    <input name="_token" type="hidden" value="{{ csrf_token() }}">
    <input type="text" name="name" placeholder="name">
    {!! Geetest::render() !!}
    <input type="submit" value="submit">
</form>

It will render like this:

When you click the submit button, it will verify the Geetest Code. If you didn't complete the validation, it will alert some text and prevent the form from submitting.

Or you can set other style of Geetest:

{!! Geetest::render('float') !!}
{!! Geetest::render('bind') !!}
{!! Geetest::render('popup') !!}
{!! Geetest::render('custom') !!}

Then it will be embed or popup style in the website. Default to float.

If the validation is completed, the form will be submitted successfully.

Server Validation

What's the reason that Geetest is safe? If it only has client validation of frontend, can we say it is complete? It also has server validation to ensure that the post request is validate.

First I have to say that you can only use Geetest of Frontend. But you can also do simple things to achieve server validation.

You can use $this->validate() method to achieve server validation. Here is an example:

use Illuminate\Http\Request;

class BaseController extends Controller 
{
    /**
     * @param Request $request
     */
    public function postValidate(Request $request)
    {
        $this->validate($request, [
            'geetest_challenge' => 'geetest',
        ], [
            'geetest' => config('geetest.server_fail_alert')
        ]);
        return true;
    }
} 

If we use Geetest, the form will post three extra parameters geetest_challenge geetest_validate geetest_seccode. Geetest use these three parameters to achieve server validation.

If you use ORM, we don't need to add these keys to Model, so you should add following in Model:

protected $guarded = ['geetest_challenge', 'geetest_validate', 'geetest_seccode'];

You can define alert text by altering server_fail_alert in config/geetest.php

Also you can use Request to achieve validation:

<?php namespace App\Http\Requests;
use App\Http\Requests\Request;

class ValidationRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'geetest_challenge' => 'geetest'
        ];
    }

    /**
     * Get validation messages.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'geetest' => 'Validation Failed'
        ];
    }
}

We can use it in our Controller by Request parameter:

use Illuminate\Support\Facades\Config;
use Illuminate\Http\Request;
use App\Http\Requests\ValidationRequest;

class BaseController extends Controller 
{
    /**
     * @param Request $request
     */
    public function postValidate(ValidationRequest $request)
    {
        // is Validate
    }
} 

Options

Change Ajax Url

If you want to change the Geetest Ajax Url, you can configure it in config/geetest.php, change url as you like, but at this time you need to add extra routes in your routes.php (Laravel 5.2 or former ) or routes/web.php (Laravel 5.3 or later). And you need to add a triat in your controller.

For example, If you add this route:

Route::get('auth/geetest','Auth\AuthController@getGeetest');

you need to add Germey\Geetest\GeetestCaptcha in your AuthController:

use Germey\Geetest\GeetestCaptcha;
class AuthController extends Controller {
    use GeetestCaptcha;
}

Then an Ajax url is configured successfully.

Also you can use this Trait in other Controller but you need to configure url in config/geetest.php.

Configure Url while rendering

Also, you can set Geetest Ajax Url by following way:

{!! Geetest::setGeetestUrl('/auth/geetest')->render() !!}

By setGeetestUrl method you can set Geetest Ajax Url. If it is configured, it will override url configured in config/geetest.php.

Configure Alert Message

You can configure alert message by configure client_fail_alert and server_fail_alert in config/geetest.php.

Configure Language

Geetest supports different language:

  • Simplified Chinese
  • Traditional Chinese
  • English
  • Japanese
  • Korean

You can configure it in config/geetest.php .

Here are key-values of Languge Configuration:

  • zh-cn (Simplified Chinese)
  • zh-tw (Traditional Chinese)
  • en (English)
  • ja (Japanese)
  • ko (Korean)

for example, If you want to use Korean, just change lang key to ko:

'lang' => 'ko'

Configure Protocol

You can configure protocol in config/geetest.php .

for example, If you want to use https, just change protocol key to https:

'protocol' => 'https'

Configure Default Product

You can configure default product in config/geetest.php .

for example, If you want to use popup product, just change product key to popup:

'product' => 'popup'

Mind that it only works when you use like this:

{!! Geetest::render() !!}

If you use like this:

{!! Geetest::render('bind') !!}

It will override the configuration in config/geetest.php.

Contribution

If you find something wrong with this package, you can send an email to [email protected]

Or just send a pull request to this repository.

Pull Requests are really welcomed.

Author

Germey , from Beijing China

License

Laravel Geetest is licensed under The MIT License (MIT).

More Repositories

1

ProxyPool

Proxy Pool System
Python
673
star
2

ValentinesDay

My LOVE
JavaScript
246
star
3

AwesomeWebScraping

List of libraries, tools and APIs for web scraping and data processing.
Makefile
232
star
4

TouTiao

TouTiao Spider Demo
Python
174
star
5

CookiesPool

CookiesPool Based on Redis
Python
153
star
6

ADSLProxyPool

Adsl Proxy Pool
Python
135
star
7

Zhihu

Zhihu User Spider
Python
131
star
8

TaobaoMM

WebSpider of TaobaoMM developed by PySpider
Python
105
star
9

AwesomeWebSpider

Awesome WebSpider
81
star
10

TaobaoProduct

Selenium Demo of Taobao Product
Python
81
star
11

AutoProxy

Auto Proxy
Python
74
star
12

CrackCaptcha

Crack Captcha Using TensorFlow
Python
72
star
13

MaoYan

MaoYan Top100 Spider
Python
60
star
14

SentenceDistance

Sentence Distance
Python
54
star
15

TaobaoUser

Get anonymous user of Taobao
Python
49
star
16

Weibo

Weibo Spider
Python
48
star
17

BiLSTMWordBreaker

Bi LSTM Word Breaker
Python
36
star
18

Weixin

Weixin Proxy Spider Demo
Python
34
star
19

ProxyFilter

Proxies Pool, Not Same As Germey/ProxyPool
Python
31
star
20

AQIStudy

JavaScript
23
star
21

DragCaptcha

Drag Captcha
Vue
20
star
22

AdslProxy

Python
17
star
23

Blog

My Personal Blog
HTML
14
star
24

Python3NoteBooks

Python3 WebSpider Notebooks
Jupyter Notebook
14
star
25

JMeterMonitor

JMeter Tester with Influxdb and Grafana
Dockerfile
13
star
26

ScrapyTutorial

Scrapy Tutorial
Julia
11
star
27

2048

Game 2048 By HTML5
JavaScript
11
star
28

AwesomeTextSummarization

Awesome Text Summarization
10
star
29

TextSummarization

Text Summarization
Python
8
star
30

Fetion

Send Message By Fetion
PHP
8
star
31

ChatGPTPluginStarter

ChatGPT Plugin Starter
Python
8
star
32

Kubernetes

Deployments on Kubernetes
Python
8
star
33

TaobaoComments

Scrape comments of products by spider
Python
8
star
34

PyPinyinTest

Demo of PyPinyin
Python
8
star
35

Pangu2

Pangu2
Python
7
star
36

TestProxy

Test speed of proxy service
Python
7
star
37

BootStrapFlex

BootStrapFlex
CSS
7
star
38

wechatpay

A HTML Page About Wechat Pay
HTML
6
star
39

MultiturnSelection

Multiturn Selection From: https://github.com/MarkWuNLP/MultiTurnResponseSelection
Python
6
star
40

Python3

Python3 Knowledge
6
star
41

Space

Why not space?
Vue
6
star
42

MNIST

Mnist Learn
Python
5
star
43

TextImage

Image with Text
Python
5
star
44

DangDang

DangDang QRCode
HTML
4
star
45

LSTMClassification

LSTM Classification on MNIST
Python
4
star
46

GulpBootStrapSass

A Gulp Demo Of Compiling Bootstrap Sass
Ruby
4
star
47

GraphMovies

Python
4
star
48

PythonOOP

Python OOP Demo
Python
4
star
49

Seq2Seq

Seq2Seq Model
Jupyter Notebook
4
star
50

Finger

Collector of Finger Gestures
HTML
3
star
51

EggTest

Build Project to Egg File and Execute it
Python
3
star
52

PPPoE

Python Scripts of PPPoE
Python
3
star
53

SDUCourse

Select Course of SDU
Python
3
star
54

Nmt

Nmt Project implemented by Tensorflow
Python
3
star
55

GermeyTechnology

Home of Germey Technology
CSS
3
star
56

AbnormalTrajectoryDetection

Source code of Abnormal Trajectory Detection
Jupyter Notebook
3
star
57

DeployBash

Deploy Bashes
Shell
2
star
58

LaravelGenerator

Laravel Generator modified from Infyom Generator by Germey
PHP
2
star
59

VideoRandomMarker

Video Random Marker
Python
2
star
60

FontCompress

Font Compress Demo
JavaScript
2
star
61

TensorFlowBasis

Basic TensorFlow Knowledge
Python
2
star
62

Audios

Audios Spider
Python
2
star
63

aboutme

A HTML Page About Me
CSS
2
star
64

PHPLogin

PHP
2
star
65

Cnki

Cnki Code Demo
Python
2
star
66

MachineLearningClassification

Machine Learning Classification
Jupyter Notebook
2
star
67

TantanImage

Tantan Image
Python
2
star
68

RandomChoose

Random Choose Based on Weitghts
Jupyter Notebook
2
star
69

PySpiders

Demos of PySpiders
Python
1
star
70

DiscordProxy

Discord Proxy
JavaScript
1
star
71

Coders

Coders' pages
CSS
1
star
72

GermyGallery

A Gallery Display
JavaScript
1
star
73

Search

Search Flask Demo
HTML
1
star
74

PointerGenerator

Pointer Generator from Abisee
Python
1
star
75

MarshMallowTest

Python
1
star
76

MidjourneyAPI

Midjourney API Usage and Free trial
1
star
77

LumaAPI

Luma API and Free Trial
1
star
78

SunoAPI

Suno API and Free Trial
1
star
79

Hack

Hack Programming
Python
1
star
80

lightbox

A Demo Of LightBox
JavaScript
1
star
81

DialogGeneration

Dialog Generation
Python
1
star
82

Quote

Quote Scrapy Demo
Julia
1
star
83

TensorFlowLayers

TensorFlow Layers Demo
Python
1
star
84

Segment

Segment Demo
Python
1
star
85

SingalRLearn

Singal R Learn
C#
1
star
86

TypingTest

Typing Test Demo
Python
1
star
87

Emissary

Allows you to easily use Laravel Service Providers with Slim 3's DI container
PHP
1
star
88

LoggingTest

Logging Test
Python
1
star
89

HaoYangMao

Hao Yang Mao
1
star
90

sendmail

A PHP Demo Of SMTP Mail Sending
PHP
1
star
91

TestDjangoRestAPI

Test Django Rest API
Python
1
star
92

YZL

Yin Zhaolong's Page
PHP
1
star
93

LaravelSweetAlert

Laravel Sweet Alert Package
CSS
1
star
94

MachineLearning

Python
1
star
95

CanvasDemo

Some Canvas Demo Reposted By Me While Learning.
HTML
1
star
96

SlimSupport

Slim Support Classes
PHP
1
star
97

GermyCMS

My CMS Developed By Laravel Named Germy
JavaScript
1
star
98

AttitudeDetection

Jupyter Notebook
1
star
99

EmailComplete

A Demo Of Email Auto Complete
JavaScript
1
star
100

GermeyCMSDemo

GermeyCMS Framework Developed by Laravel
JavaScript
1
star