验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

PHP如何实现滑块验证图片

阅读:968 来源:乙速云 作者:代码code

PHP如何实现滑块验证图片

安装

composer require kkokk/poster

更新

composer update kkokk/poster

使用文档

开源仓库:
gitee 文档
github 文档

    use KkokkPosterPosterManager;
    use KkokkPosterExceptionPosterException;

    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())
    }

分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>