Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that the thinkphp verification code is not valid

Shulou Source: shulou.com Published: 2022-06-02 05:14:23 10月03日 Update

This article mainly introduces how to solve the problem of invalid thinkphp CAPTCHA, which is very detailed and has a certain reference value. Friends who are interested must finish it!

The solution that thinkphp CAPTCHA does not take effect: 1, add "ob_clean ();" statement before calling CAPTCHA; 2, check your database configuration file and modify it correctly.

This article operating environment: Windows7 system, thinkphp v5.1, Dell G3 computer.

The reason and solution of not displaying ThinkPHP5 CAPTCHA

In fact, I encountered this problem when I first learned the tp5 framework a long time ago, and there has been no problem since it was solved. Today, I encountered this problem again when I used the previous framework to do a new project. Here's a record.

The cause of the problem:

1. TP5 already exists this bug.

2. The database connection is abnormal (the verification code will not be displayed when the project connection to the database is abnormal)

Solution:

1. TP5 itself bug, in the TP5 official website forum is given the corresponding solution, before obtaining the verification code to clear the cache on it

/ * * get the verification code * * / public function getVerify () {$config = ['fontSize' = > 28,' length' = > 4, 'useCurve' = > false,]; ob_clean (); / / clear the cache $captcha = new Captcha ($config) each time before getting the verification code; return $captcha- > entry () }

Analysis:

What the function ob_clean does:

It is used to discard the contents of the output buffer. If your site has many generated image files, you should always clear the buffer if you want to access it correctly.

2. If the database connection is abnormal, check whether there is a problem with your database configuration file. Tp5 database configuration file dababase.php

Return [/ / database type 'type' = >' mysql', / / server address' hostname' = >', / / database name 'database' = >', / / user name 'username' = > root, / / password' password' = >'' / / port 'hostport' = >' 3306', / / connection dsn' dsn' = >'', / / database connection parameter 'params' = > [], / / database code defaults to utf8' charset' = >' utf8', / / database table prefix 'prefix' = >' ww_' / / Database debugging mode 'debug' = > true, / / Database deployment mode: 0 centralized (single server), 1 distributed (master-slave server)' deploy' = > 0, / / whether the database read and write is separated from master-slave effective 'rw_separate' = > false / / after the separation of reads and writes, the number of master servers' master_num' = > 1, / specify the slave server serial number 'slave_no' = >'', / / strictly check whether the field exists' fields_strict' = > true, / / dataset return type 'resultset_type' = >' array' / / automatically write the timestamp field 'auto_timestamp' = > true, / / the default time format after the time field is taken out is' datetime_format' = > 'Y-m-d, / / whether SQL performance analysis is required' sql_explain' = > false,] The above is all the contents of this article entitled "how to solve the problem of invalid thinkphp CAPTCHA". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Data database validation problem server service file content field method time check configuration incorrect master-slave reason framework article type buffer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Linux vpn Apple Shulou Tech Info