<?php
namespace Home\Controller;
use Think\Controller;
use Home\Model\loginModel;
class TestController extends Controller
{
public function Add ()
{
/*$login=D("login");*/
$login=new loginModel();
//var_dump($login);
//var_dump($login->select());
if(empty($_POST))
{
$this->display();
}
else
{
$z= $login->create();
//var_dump ($z);
if($z)
{
echo "This Is Ok";
//$login->add();
}
else
{
$str=$login->getError();
$this->assign("error",$str);
$this->display();
}
}
}
public function YZM()
{
$config=array(
'useImgBg' => true, // 使用背景图片
'fontSize' => 25, // 验证码字体大小(px)
'useCurve' => true, // 是否画混淆曲线
'useNoise' => true, // 是否添加杂点
'imageH' => 0, // 验证码图片高度
'imageW' => 0, // 验证码图片宽度
'length' => 5, // 验证码位数
'useZh' => true,
'fontttf' => 'STKAITI.TTF', // 验证码字体,不设置随机获取
'bg' => array(243, 251, 254), // 背景颜色
'reset' => true, // 验证成功后是否重置
);
$v=new\Think\Verify($config);
$v->entry();
}
public function Denglu()
{
if(empty($_POST))
{
$this->display();
}
else
{
$v=new\Think\Verify();
$z=$v->check($_POST["YZM"]);
var_dump($z);
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="../../../../../jq.js"></script>//引入路径一定要注意,最好是绝对路径
</head>
<body>
<form action="__SELF__" method="post" >
<div>用户名:<input type="text" name="UserName" /></div>
<div>密码:<input type="text" name="Password" /></div>
<div>验证码:<img id="yzm" src="__CONTROLLER__/YZM" /><input type="text" name="YZM" /></div>
<div><input type="submit" value="登录" /></div>
</form>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(e) {
$("#yzm").click(function(){
var str = "a/"+Math.random();//火狐浏览器不加随机数有缓存
$(this).attr("src","__CONTROLLER__/YZM/"+str);
}
)
});
</script>