您好,欢迎访问一九零五行业门户网

工具包分享:PHP实现滑块验证图片

本篇文章主要给大家介绍php如何实现滑块验证图片,这里分享一个工具包“poster”,下面看看怎么实现吧,希望对需要的朋友有所帮助!
【推荐学习:php视频教程】
安装composer require kkokk/poster
更新composer update kkokk/poster
使用文档开源仓库:
gitee 文档
github 文档
    use kkokk\poster\postermanager;    use kkokk\poster\exception\posterexception;    try {        # 滑块自定义参数        $params = [            'src'           => '',  // 背景图片,尺寸 340 * 191            'im_width'      => 340, // 画布宽度            'im_height'     => 251, // 画布高度            'bg_width'      => 340, // 背景宽度            'bg_height'     => 191, // 背景高度            'slider_width'  => 50,  // 滑块宽度            'slider_height' => 50,  // 滑块高度            'slider_border' => 2,   // 滑块边框        ];        $type = 'slider';        /**          * 获取滑块验证参数          * 内部使用了 laravel 的 cache 缓存,返回的是图片的 base64 、 缓存key 、滑块高度          * @param string $type   验证码类型          * @param array  $params 验证码自定义参数          * @return arary          */        $data = postermanager::captcha()->type($type)->config($params)->get();        /**           * 验证滑块          * 前端根据相关滑块操作进行处理, 返回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())    }
示例
以上就是工具包分享:php实现滑块验证图片的详细内容。
其它类似信息

推荐信息