Home >Backend Development >PHP Tutorial >Simple method to use verification code in thinkPHP
The example in this article describes the simple use of verification code in thinkPHP. Share it with everyone for your reference, the details are as follows:
First generate the verification code. In the action file, directly call the method provided in thinkphp to generate it. Make sure to enable the php extension gd2
as follows:
class UserAction Model extends Model { /** * 显示验证码信息 */ public function verify() { ob_clean(); // 清空(擦掉)输出缓冲区 ,也就是清空前面的输出,通常情况下验证码不显示,可考虑这个问题 import('ORG.Util.Image'); Image::buildImageVerify(); } }
Use both at the same time SESSION saves the value of the generated verification code:
Copy the code The code is as follows:
$_SESSION['verify']
In the corresponding tpl file, call the verification code. The usage method is as follows:
Copy the code The code is as follows:
The user submits the verification code in the past, which needs to be encrypted by md5 and then compared with the saved session value, that is:
Judge md5($_POST['verify'] and $ _SESSION['verify'] is equal.
This completes the basic use of the verification code
I hope this article will be helpful to everyone’s PHP program design based on the thinkPHP framework.
The above introduces the simple method of using verification code in thinkPHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.