Home > Article > Backend Development > Toolkit sharing: PHP implements slider verification pictures
This article mainly introduces how to implement slider verification pictures in PHP. Here I share a toolkit "poster". Let's see how to implement it. I hope it will be helpful to friends in need!
[Recommended learning: PHP video tutorial]
composer require kkokk/poster
composer update kkokk/poster
Open source repository:
gitee documentation
github documentation
use Kkokk\Poster\PosterManager; use Kkokk\Poster\Exception\PosterException; try { # Toolkit sharing: PHP implements slider verification pictures自定义参数 $params = [ 'src' => '', // 背景图片,尺寸 340 * 191 'im_width' => 340, // 画布宽度 'im_height' => 251, // 画布高度 'bg_width' => 340, // 背景宽度 'bg_height' => 191, // 背景高度 'slider_width' => 50, // Toolkit sharing: PHP implements slider verification pictures宽度 'slider_height' => 50, // Toolkit sharing: PHP implements slider verification pictures高度 'slider_border' => 2, // Toolkit sharing: PHP implements slider verification pictures边框 ]; $type = 'slider'; /** * 获取Toolkit sharing: PHP implements slider verification pictures验证参数 * 内部使用了 laravel 的 cache 缓存,返回的是图片的 base64 、 缓存key 、Toolkit sharing: PHP implements slider verification pictures高度 * @param string $type 验证码类型 * @param array $params 验证码自定义参数 * @return arary */ $data = PosterManager::Captcha()->type($type)->config($params)->get(); /** * 验证Toolkit sharing: PHP implements slider verification pictures * 前端根据相关Toolkit sharing: PHP implements slider verification pictures操作进行处理, 返回x坐标,返回 true 则验证成功 * @param string $key 缓存key * @param string|int $value 前端传回来的x坐标 * @param int $leeway 误差值 * @return boolean */ $res = PosterManager::Captcha()->type($type)->check($key, $value, $leeway); } catch (PosterException $e) { print_r($e->getMessage()) }
The above is the detailed content of Toolkit sharing: PHP implements slider verification pictures. For more information, please follow other related articles on the PHP Chinese website!