PHP code example of laravist / geecaptcha

1. Go to this page and download the library: Download laravist/geecaptcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravist / geecaptcha example snippets


 $captcha = new \Laravist\GeeCaptcha\GeeCaptcha($captcha_id, $private_key);

 if ($captcha->isFromGTServer() && $captcha->success()) 
 {
     // 登录的代码逻辑在这里   
 }


$captcha = new \Laravist\GeeCaptcha\GeeCaptcha($captcha_id, $private_key);
echo $captcha->GTServerIsNormal();

Route::group(['middleware' => ['web']], function () {
    Route::get('/login', function () {
        return view('login');
    });

    Route::post('/verify', function () {
        $captcha = new \Laravist\GeeCaptcha\GeeCaptcha(env('CAPTCHA_ID'), env('PRIVATE_KEY'));
        if ($captcha->isFromGTServer()) {
            if($captcha->success()){
                return 'success';
            }
            return 'no';
        }
        if ($captcha->hasAnswer()) {
                return "answer";
        }
        return "no answer";
    });

    Route::get('/captcha', function () {
        $captcha = new \Laravist\GeeCaptcha\GeeCaptcha(env('CAPTCHA_ID'), env('PRIVATE_KEY'));

        echo $captcha->GTServerIsNormal();
    });

});