Simple implementation method of thinkPHP5.0 framework verification code call and click picture refresh
- 2021-11-02 00:09:04
- OfStack
This paper describes the implementation method of thinkPHP5.0 framework verification code call and click picture refresh. Share it for your reference, as follows:
1. Add verification code configuration to the configuration file
'captcha' => [
// Verification code character set
'codeSet' => '23456789',
// Verification code font size (px)
'fontSize' => 25,
// Whether to draw confusion curve
'useCurve' => false,
// Verification code number
'length' => 4,
// Reset after successful verification
'reset' => true
],
2. The back-end verification code method is written
public function check($code='')
{
if (!captcha_check($code)) {
$this->error(' Verification code error ');
} else {
return true;
}
}
3. The front end calls the verification code and sets the onclick attribute. Click the picture to refresh the verification code
<div>
<span><strong> Please enter the verification code </strong></span>
<input display: inline;" class="form-control" name="code" type="text" required="required">
<img src="{:captcha_src()}" onclick="this.src='{:captcha_src()}?'+Math.random();"/>
</div>
Readers who are interested in thinkPHP can check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "codeigniter Introduction Tutorial", "CI (CodeIgniter) Framework Advanced Tutorial", "Zend FrameWork Framework Introduction Tutorial" and "PHP Template Technology Summary".
I hope this article is helpful to PHP programming based on ThinkPHP framework.