Toolkit sharing: PHP implements slider verification pictures

藏色散人
Release: 2023-04-11 09:08:01
forward
6673 people have browsed it

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]

Installation

composer require kkokk/poster
Copy after login

Update

composer update kkokk/poster
Copy after login

Usage documentation

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())
    }
Copy after login

Example

Toolkit sharing: PHP implements slider verification pictures

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!