TP5 验证码

application\index\controller\Index.php

<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    public function check($code='')
    {
        $captcha = new \think\captcha\Captcha();
        if(!$captcha->check($code)) {
            $this->error('验证码错误');
        }else{
            $this->success('验证码正确');
        }
    }
}

application\index\view\index\index.html

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<FORM method="post" action="{:url('check')}">
	<p>
		<input name="code" type="text" placeholder="请输入验证码" style="width: 100px;">
		<span>
			<img class="captcha" src="{:captcha_src()}" alt="请点击刷新验证码"
			onclick="this.src='{:captcha_src()}'+'?'+Math.random()" />
		</span>
	</p>
	<p style="margin-top: 30px;">
		<input type="submit" class="button" value="提交">
	</p>
</FORM>
</body>
</html>

效果图:

 

猜你喜欢

转载自onestopweb.iteye.com/blog/2386499