. This can also be achieved by changing the parameters of the verification code. The fontSize parameter refers to the font size of the verification code."/> . This can also be achieved by changing the parameters of the verification code. The fontSize parameter refers to the font size of the verification code.">

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

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-08-26 16:46:402616browse

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();  
}
public function shengcheng()
{
    //造验证码的对象
    $v = new \Think\Verify();
    //生成验证码
    $v->entry();
}

(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" >

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" >

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();

2. Dynamic settings:

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

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!

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
Previous article:How to deploy thinkPHPNext article:How to deploy thinkPHP