top-think / think-captcha Goto Github PK
View Code? Open in Web Editor NEWthinkphp 验证码类库
License: Other
thinkphp 验证码类库
License: Other
在lamp中搭建的tp6项目中,只有第一次的时候可以验证通过,若刷新页面再次验证的话,就会不通过,即便删除浏览器缓存仍然不行,求指教下
composer 已经把包下载下来了
use think\captcha;
{:captcha_src()}
输出了:/captcha.html
路由是否需要配置?配置指向哪里?
3.0.5版本的验证码图片显示不全啊,4个字符的只显示3个,回退到3.0.4就正常了
我的群里某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);
}
}
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的composer库,静待官方更新, 小伙伴们可以先用我们这个
composer require zjkal/think-captcha
这个github库
https://github.com/zjkal/think-captcha
我用的版本是:v1.0.7
Captcha.php 293行,图片路径好像写错了,能修复一下吗 😊 😊
路由里面定义的
Route::get('login/index', "\think\captcha\CaptchaController@index");
在页面无法正常显示
mt_rand小数在php8.1报错
本来更新前,四位数好好的,更新后就只能显示3位数,其余被遮挡,不设置宽高也一样,中英文和算术都有这个问题
验证码生成错误。是不是要依赖什么扩展?但是composer.json里面并没有声明啊
验证码原作者2009年发布代码iteye http://www.iteye.com/topic/469170
使用的是new bsd协议,使用抄袭原作者代码需保留版权,你已侵权。
我在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); }
合并不会覆盖默认参数
前后端分离项目没有用session,希望能支持API方式,谢谢!
求升级兼容5.1RC
[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);
}
// 执行操作方法
Line 314 in 54c8a51
/* 加密验证码 */
private function authcode($str)
{
$key = substr(md5($this->seKey), 5, 8);
$str = substr(md5($str), 8, 10);
return md5($key . $str);
}
为什么要截取6-14位和 9-18位呢? 请大佬解惑,谢谢。
thinkphp5 验证码类库能使用git进行安装吗?或者是只能使用composer来安装,使用composer的时候各种恶心的报错
//test.php in test folder
require_once DIR.'/../vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {} catch (Exception $e) {}
php8.1,float类型转换报错,请官方尽快修复一下吧?
假如我有两个站点,分别是www.aaa.com和api.bbb.com,我的bbb.com站点提供了注册接口,当a站点想要发送注册请求时,会带上b站点给它提供的验证码(http://api.bbb.com/verifycode.html)。因为我们的验证码是使用session进行存储,我看到,咱们会生成一个sessionid。收到浏览器同源问题的限制,当a站点通过ajax请求注册时,并不会带上sessionid。所以会导致验证码失效,无法通过请求。
我不知道自己是否表达清楚,我觉得应该考虑到这样的问题,或者我们可以增加一个配置选项,可以让用户自由选择使用何种方式缓存验证码!
配置文件修改length后会导致math验证图片显示不完整
$this->length = 5;
对 create() 方法无效protected function generate(): array
{
$bag = '';
if ($this->math) {
$this->length = 5;
public function create(string $config = null, bool $api = false): Response
{
$this->configure($config);
if($this->math){
$this->length = 5;
}
#0 [8192]ErrorException in Captcha.php line 181
$this->im = imagecreate($this->imageW, $this->imageH); 报错
点击后的路径是
http://nfc.tp6.com/captcha.html?s=0.008023090088682183
会认为是控制器
控制器不存在:0.008023090088682183
if (!$this->session->has('captcha')) {
return false;
}
这句话报错 ,session里没有captcha
如题。
比如使用vendor\bin\phinx init,报错Route类不存在,因为TP并没有启动。
问题所在:
helper.php是自动引入的
如题,直接使用\think\Route::get会报错误,应该使用think\facade\Route 同理URL也是
我控制器中写了两个生成验证码的方法:
public function captcha(){
return Captcha::create(1);
}
public function captcha2(){
return Captcha::create(2);
}
然后在同一张页面同时调用这两个验证码,分别对应两个输入框,请问如何使用Captcha::check()进行区分验证?tp6之前的验证码类库,check方法是可以传递id标识的呀
既然路由是针对应用的,那么在应用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}" : ''));
请问这样会不会有其他问题呢?
如果没有别的防御,就单看这个验证,验证失败后没有清空session,那就可以暴力破解直到正确的为止,是不是这样?
我在最后返回之前加了清除Session::delete($key, '');
如果我建立一个admin模块,并单独配置session,这时在控制器中验证前端发送过来的验证码不成功!模块配置session与公共配置session存在差异,导致验证失败。
感谢@bolo✔ 找出问题根源,感谢tinkphp做出的贡献。
captcha()
获取验证码的时候,报 Call to undefined function captcha()
use think\captcha\facade\Captcha;
导入 Captcha
类的时候仍然是找不到该类建议helper.php的所有函数
if (!function_exists('captcha')) {
}
亲,你的验证码类参考我很多年前写的这个代码,http://www.iteye.com/topic/469170。
参考成分太大了,至少也该有个参考备注吧。
另外我写的未正式发布框架(https://github.com/windwork)欢迎来访。
<?php
namespace think\captcha\facade;
use think\Facade;
/**
* Class Captcha
* @package think\captcha\facade
* @mixin \think\captcha\Captcha
*/
class Captcha extends Facade
{
protected static function getFacadeClass()
{
return 'think\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.
安装该库后会导致启动swoole服务后第一次打开页面没有加载路由而导致报错,刷新一下就正常打开了
删除该库后就正常了
我的php版本是7.0的,难道是因为版本的问题?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.