PHP code example of yprisoner / mexcaptcha
1. Go to this page and download the library: Download yprisoner/mexcaptcha 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/ */
yprisoner / mexcaptcha example snippets
$app->configure('mexcaptcha');
$app->register(MexCaptcha\Providers\MexCaptchaServiceProvider::class);
'cache_handler' => \App\Handler\CaptchaCacheHandler::class // implements MexCaptcha\Contracts\CacheHandlerInterface
/**
* # ----
* # Yprisoner <[email protected] >
* # 2019/8/10 21:37
* # ------
**/
namespace App\Handler;
use MexCaptcha\Contracts\CacheHandlerInterface;
class CaptchaCacheHandler implements CacheHandlerInterface {
/**
* Get cache value by cache Key.
*
* @param string $key
* @return string
*/
public function get (string $key): string {
// TODO: Implement get() method.
}
/**
* Set a cache.
*
* @param string $key
* @param string $value
* @param int $expired_at
* @return mixed
*/
public function set (string $key, string $value, int $expired_at) {
// TODO: Implement set() method.
}
/**
* Determine if the cache exists.
*
* @param string $key
* @return bool
*/
public function has (string $key): bool {
// TODO: Implement has() method.
}
/**
* Remove s cache by Key.
*
* @param string $key
* @return mixed
*/
public function del (string $key) {
// TODO: Implement del() method.
}
}
/**
* # ----
* # Yprisoner <[email protected] >
* # 2019/8/10 21:39
* # ------
**/
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use MexCaptcha\Contracts\CaptchaInterface;
use MexCaptcha\Support\Str;
class CaptchaController extends Controller {
/**
* @param Request $request
* @return array
*/
public function getCaptchaInfo (Request $request) {
// ......
$server_url = $request->getSchemeAndHttpHost();
$captcha_id = mexcaptcha_uuid();
return [
'captcha_url' => $server_url . "/captcha/{$captcha_id}",
'captcha_id' => $captcha_id
];
}
/**
* 显示验证码图片
*
* @param Request $request
* @param string $captcha_id
* @return mixed
*/
public function showCaptchaImage (Request $request, string $captcha_id) {
return mexcaptcha()->create($captcha_id);
}
/**
* @param Request $request
* @param string $captcha_id
* @return array
*/
public function doSomeThing (Request $request, string $captcha_id) {
$validator = Validator::make($request->all(), [
'captcha_code' => '