Home >PHP Framework >ThinkPHP >How to solve the problem that thinkphp verification code does not take effect
Thinkphp verification code does not take effect solution: 1. Add the "ob_clean();" statement before calling the verification code; 2. Check your database configuration file and modify it correctly.
#The operating environment of this article: Windows 7 system, thinkphp v5.1 version, Dell G3 computer.
How to solve the problem that thinkphp verification code does not take effect?
The reason why the ThinkPHP5 verification code is not displayed and the solution
In fact, I encountered this problem a long time ago when I just learned the tp5 framework. After solving it, I still have No more problems occurred. Today I encountered this problem again when using the previous framework for a new project. Here is a record of
The cause of the problem:
1. TP5 is inherently There is this bug
2. The database connection is not normal (the verification code will not be displayed when the project connection to the database is not normal)
Solution:
1. TP5’s own bugs are solved by corresponding methods in the TP5 official website forum. Just clear the cache before getting the verification code
/* * 获取验证码 * */ public function getVerify() { $config = [ 'fontSize' => 28, 'length' => 4, 'useCurve' => false, ]; ob_clean(); //每次获取验证码前都清除下缓存 $captcha = new Captcha($config); return $captcha->entry(); }
Analysis:
The role of ob_clean function:
Used to discard the content in the output buffer. If your website has many generated image files, then if you want to access them correctly, you must clear the buffer frequently.
2. Due to abnormal database connection, check if there is any problem with your database configuration file. The tp5 database configuration file dababase.php
return [ // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => '', // 数据库名 'database' => '', // 用户名 'username' => root, // 密码 'password' => '', // 端口 'hostport' => '3306', // 连接dsn 'dsn' => '', // 数据库连接参数 'params' => [], // 数据库编码默认采用utf8 'charset' => 'utf8', // 数据库表前缀 'prefix' => 'ww_', // 数据库调试模式 'debug' => true, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) 'deploy' => 0, // 数据库读写是否分离 主从式有效 'rw_separate' => false, // 读写分离后 主服务器数量 'master_num' => 1, // 指定从服务器序号 'slave_no' => '', // 是否严格检查字段是否存在 'fields_strict' => true, // 数据集返回类型 'resultset_type' => 'array', // 自动写入时间戳字段 'auto_timestamp' => true, // 时间字段取出后的默认时间格式 'datetime_format' => 'Y-m-d H:i:s', // 是否需要进行SQL性能分析 'sql_explain' => false, ];
Recommended study: "The latest 10 thinkphp video tutorials》
The above is the detailed content of How to solve the problem that thinkphp verification code does not take effect. For more information, please follow other related articles on the PHP Chinese website!