Home  >  Article  >  Backend Development  >  How to solve the problem of invalid php verification code

How to solve the problem of invalid php verification code

藏色散人
藏色散人Original
2022-11-10 10:34:141751browse

php验证码失效的解决办法:1、开启gd2选项;2、使用windows自带的记事本编辑器对网站配置文件进行修改和保存;3、使用“ob_clean()”方法清除相关缓存;4、重写规则“.htaccess”;5、开启Redis服务即可。

How to solve the problem of invalid php verification code

本教程操作环境:windows7系统、PHP8.1版、Dell G3电脑。

怎么解决php验证码失效问题?

PHP页面验证码失效不显示问题解决

笔者也是刚接触php,难免会出现很多问题,导入项目的时候就出现了验证码失效不显示的问题。本地配置了phpstudy集成服务,php版本是5.6.9,thinkphp为3.2.2

How to solve the problem of invalid php verification code

方案一:开启gd2选项

     使用 PHP 处理图像就需要 GD 库的支持

How to solve the problem of invalid php verification code

     在php安装目录下面的php.ini的文件中开启extension = php_gd2.dll配置,去除前面的“;”符号即可。

How to solve the problem of invalid php verification code

     在phpstudy中开启gd2步骤,点击管理->php扩展->php_gd2开启。我们可以通过使用

phpphpinfo();?>去查看gd选项是否开启。

How to solve the problem of invalid php verification code

方案二:无bom utf-8格式

     或是使用windows自带的记事本编辑器对网站一些配置文件进行修改和保存,导致编码格式发生变化,由无bom的utf-8变成了utf-8。可以使用Notepad++进行转码,将utf-8转成无bom的utf-8。不过笔者不是这个问题。

How to solve the problem of invalid php verification code

方案三:ob_clean

How to solve the problem of invalid php verification code

     在生成验证码之前,使用ob_clean()方法清除相关缓存,但笔者的问题也不在这里。

方案四:.htaccess 重写规则

How to solve the problem of invalid php verification code

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^static/(.*)$ tpl/theme/default/static/$1 [L]
 RewriteRule ^tpl/theme/default/(.*)$ tpl/theme/default/$1 [L]
 RewriteRule ^Public/(.*)$ Public/$1 [L]
 RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>

     最后发现是没有配置.htaccess重写规则导致的。

How to solve the problem of invalid php verification code

方案五:开启Redis服务

     有些项目配置了redis缓存服务,需要将其开启,还需要将phpstudy的php扩展中的php_redis勾选,最后重启服务即可。

How to solve the problem of invalid php verification code

推荐学习:《PHP视频教程

The above is the detailed content of How to solve the problem of invalid php verification code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn