Home > PHP Framework > ThinkPHP > How to set the width and height of thinkphp verification code

How to set the width and height of thinkphp verification code

爱喝马黛茶的安东尼
Release: 2019-08-26 16:46:40
Original
2617 people have browsed it

How to set the width and height of thinkphp verification code

#Think\Verify class can support the generation and verification functions of verification codes.

In order to display this verification code function, first there must be a controller, then there must be a method, and then there must be a displayed page.

Related recommendations: "ThinkPHP Tutorial"

The simplest way to generate a verification code:

(1) We still continue to write in that controller Method

How to set the width and height of thinkphp verification code

This method displays the page of this verification code

public function xianshi()
{
    $this->show();  
}
Copy after login
public function shengcheng()
{
    //造验证码的对象
    $v = new \Think\Verify();
    //生成验证码
    $v->entry();
}
Copy after login

(2) The page that displays the verification code should still be placed in How to set the width and height of thinkphp verification code , name it How to set the width and height of thinkphp verification code

<img  src="__CONTROLLER__/shengcheng" / alt="How to set the width and height of thinkphp verification code" >
Copy after login

Run it and see the results:

How to set the width and height of thinkphp verification code

(3) We can also set the size for it, and every time the page is refreshed, The verification code will change.

Just give him an attribute, for example:

<img  src="__CONTROLLER__/shengcheng"    style="max-width:90%"  style="max-width:90%" / alt="How to set the width and height of thinkphp verification code" >
Copy after login

Both width and height become larger

How to set the width and height of thinkphp verification code

About verification Code parameters

These parameters can be used to transform the verification code.

How to set the width and height of thinkphp verification code

Note: There are two ways to set parameters.

1. Instantiation incoming parameters:

$config = array(   
    &#39;fontSize&#39;    =>    30,    // 验证码字体大小   
    &#39;length&#39;      =>    3,     // 验证码位数   
    &#39;useNoise&#39;    =>    false, // 关闭验证码杂点
);
$Verify = new \Think\Verify($config);
$Verify->entry();
Copy after login

2. Dynamic settings:

$Verify = new \Think\Verify();
$Verify->fontSize = 30;
$Verify->length   = 3;
$Verify->useNoise = false;
$Verify->entry();
Copy after login

The above is the detailed content of How to set the width and height of thinkphp verification code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template