Giter VIP home page Giter VIP logo

think-captcha's People

Contributors

lait233 avatar liu21st avatar normal-coder avatar tianheng2017 avatar yunwuxin avatar zhaishuaigan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

think-captcha's Issues

composer 安装后,如何使用?

composer 已经把包下载下来了
use think\captcha;
{:captcha_src()}
输出了:/captcha.html
路由是否需要配置?配置指向哪里?

无法通过composer下载

composer配置没问题,安装其他包可以,但是安装think-captcha有可能会提示错误,如下:
微信截图_20190421171809
不是百分百必现的,碰到过几次。

验证码无法显示有bug

我的群里某PHPer遇到验证码无法显示的问题,经过我们一起进行原因排除,发现验证码输出前未清空缓冲池,请官方在合适的地方加上如下代码:

namespace think\captcha;

use think\Config;

class CaptchaController
{
    public function index($id = "")
    {
        $captcha = new Captcha((array)Config::get('captcha'));

       // 就是这一句
        ob_clean();

        return $captcha->entry($id);
    }
}

3.0 获取统一默认配置建议加入$config=''的支持

vendor\topthink\think-captcha\src\Captcha.php 75行

/**
     * 配置验证码
     * @param string|null $config
     */
    protected function configure(string $config = null): void
    {
        if (is_null($config)) {
            $config = $this->config->get('captcha', []);
        } else {
            $config = $this->config->get('captcha.' . $config, []);
        }

        foreach ($config as $key => $val) {
            if (property_exists($this, $key)) {
                $this->{$key} = $val;
            }
        }
    }

当$config传入空字符串''即($config='')调用无法使用自定义的配置,建议支持空字符串获取默认配置

PHP8.1兼容方案

我临时发布了一版兼容php8.1的composer库,静待官方更新, 小伙伴们可以先用我们这个

composer require zjkal/think-captcha

这个github库

https://github.com/zjkal/think-captcha

5.1RC3读取配置文件合并参数有问题

我在config下建立captcha.php里面设置
return [ // 验证码字体大小(px) 'fontSize' => 18, // 是否画混淆曲线 'useCurve' => false, // 验证码图片高度 'imageH' => 34, // 验证码图片宽度 'imageW' => 30, // 验证码位数 'length' => 3 ];
结果debug了一下,发现会把所有的参数名变成小写,导致
public function __construct($config = []) { $this->config = array_merge($this->config, $config); }
合并不会覆盖默认参数

报错 无法使用 已正确安装

[0] HttpException in App.php line 330
控制器不存在:captcha

        // 设置当前请求的控制器、操作
        $request->controller($controller)->action($actionName);

        // 监听module_init
        Hook::listen('module_init', $request);

        try {
            $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
            if (is_null($instance)) {
                throw new HttpException(404, 'controller not exists:' . $controller);
            }
            // 获取当前操作名
            $action = $actionName . $config['action_suffix'];
            if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {
                // 非法操作
                throw new \ReflectionException('illegal action name:' . $actionName);
            }

            // 执行操作方法

关于跨域请求,验证码无效的一些问题

假如我有两个站点,分别是www.aaa.com和api.bbb.com,我的bbb.com站点提供了注册接口,当a站点想要发送注册请求时,会带上b站点给它提供的验证码(http://api.bbb.com/verifycode.html)。因为我们的验证码是使用session进行存储,我看到,咱们会生成一个sessionid。收到浏览器同源问题的限制,当a站点通过ajax请求注册时,并不会带上sessionid。所以会导致验证码失效,无法通过请求。
我不知道自己是否表达清楚,我觉得应该考虑到这样的问题,或者我们可以增加一个配置选项,可以让用户自由选择使用何种方式缓存验证码!

配置文件修改length后会导致math验证图片显示不完整

配置文件修改length后会导致math验证图片显示不完整

问题出在: generate() 方法下的 $this->length = 5; 对 create() 方法无效

protected function generate(): array
{
    $bag = '';

    if ($this->math) {
        $this->length = 5;

我是这样解决的:在 create() 方法下增加一个$this->length = 5;

public function create(string $config = null, bool $api = false): Response
{
    $this->configure($config);

    if($this->math){
        $this->length = 5;
    }

rc4 验证码验证不了

if (!$this->session->has('captcha')) {
return false;
}
这句话报错 ,session里没有captcha

同一张页面中有多个验证码,如何进行区分验证?

我控制器中写了两个生成验证码的方法:

public function captcha(){
	return Captcha::create(1);
}
public function captcha2(){
	return Captcha::create(2);
}

然后在同一张页面同时调用这两个验证码,分别对应两个输入框,请问如何使用Captcha::check()进行区分验证?tp6之前的验证码类库,check方法是可以传递id标识的呀

3.0 验证码captcha_src路径问题

既然路由是针对应用的,那么在应用admin里开启路由

\think\facade\Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");

那么访问验证码的地址应该是xxx.com/admin/captcha.html
所以验证码helper.php的captcha_src中

return Route::buildUrl('/captcha' . ($config ? "/{$config}" : ''));

这里的路径是不是不能直接是/captcha呢?
建议针对多应用改进.
我现在改为:

return Route::buildUrl('./captcha' . ($config ? "/{$config}" : ''));

请问这样会不会有其他问题呢?

not found function captcha()

  • tp6 lamp环境
  • 在控制器中使用captcha()获取验证码的时候,报 Call to undefined function captcha()
  • 在控制器中使用 use think\captcha\facade\Captcha; 导入 Captcha类的时候仍然是找不到该类

安装报错,帮忙看下

bogon:~  zjh$ composer require topthink/think-captcha
Using version ^2.0 for topthink/think-captcha
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - topthink/think-captcha v2.0.1 requires topthink/framework 5.1.x-dev -> satisfiable by topthink/framework[5.1.x-dev] but these conflict with your requirements or minimum-stability.
    - topthink/think-captcha v2.0 requires topthink/framework 5.1.x-dev -> satisfiable by topthink/framework[5.1.x-dev] but these conflict with your requirements or minimum-stability.
    - Installation request for topthink/think-captcha ^2.0 -> satisfiable by topthink/think-captcha[v2.0, v2.0.1].


Installation failed, deleting ./composer.json.

该库好像与 think-swoole 不兼容

安装该库后会导致启动swoole服务后第一次打开页面没有加载路由而导致报错,刷新一下就正常打开了
删除该库后就正常了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.