


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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),