thinkphp验证码使用
在thinkphp中使用验证码很容易,只要调用thinkphp现有的方法就可以。当然,php的GD库肯定是要开的(就是在php.ini中要加载gd模块)。
thinkphp 3.1 --------------------------------------------------------------------------------- 首先,在写Action文件,如:IndexAction.class.php.
<?php
class IndexAction extends Action{
//显示验证码
public function verifyTest() {
$this->display();
} //检验验证码是否正确
public function verifyCheck() {
//防止页面乱码
header('Content-type:text/html;charset=utf-8'); if (md5($_POST['verifyTest']) != Session::get('verify')) {
echo '验证码错误';
}
else {
echo '验证码正确';
}
} // 生成验证码
public function verify() {
import("ORG.Util.Image");
Image::buildImageVerify();
}
}
?>
在对应的模板文件:Tpl\default\index目录下新建文件verifyTest.html,内容如下:
<script type='text/javascript'>
//重载验证码
function freshVerify() {
document.getElementByIdx('verifyImg').src='__URL__/verify/'+Math.random();
}
</script>
<form method='post' action='__URL__/verifyCheck'>
<input type='text' name='verifyTest'>
<img style='cursor:pointer' title='刷新验证码' src='__URL__/verify' id='verifyImg' onClick='freshVerify()'/>
<button type='submit'>确定</button>
</form> thinkphp 3.2 ----------------------------------------------------------------------------- 首先,在写Controllers文件,如:IndexController.class.php. HomeController 是继承 Controller 的父级控制器 也可以直接继承 Controller 在Home文件加下:Home\Common\function.php 添加 一个检测验证码的封装函数 <?php
function check_verify($code, $id="") {
$verify = new \Think\Verify(); return $verify->check($code, $id);
} ?> <?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends HomeController {
//显示验证码
public function index() {
$this->display();
} // 生成验证码
public function verify() {
$arr = array(
'imageW' => , //验证码显示的款地
'imageH' => , //验证码显示的高度
'fontSize'=>, //验证码字体大小
'length' => , //验证码位数
'useNoise'=>false, //关闭验证码杂点 true 开启
'useCurve'=>false, //关闭验证码曲线 true 开启
'bg' => array(,,) //设置背景色
);
$verify = new \Think\Verify($arr);
$verify->entry();
}
//校验验证码
public function verifyCheck() {
//防止页面乱码
header('Content-type:text/html;charset=utf-8');
$verify = I("post.verify");
$result = check_verify($verify);
if ($result) {
echo "验证通过!";
exit;
} else {
echo "验证码错误!";
exit;
}
} }
?>
在对应的模板文件:Views\Index\目录下新建文件index.html,内容如下:
<script type='text/javascript'>
//重载验证码
function freshVerify() {
document.getElementById('verifyImg').src='{:U("Index/verify")}?'+Math.random();
}
</script>
<form method='post' action='{:U("Index/verifyCheck")}'>
<input type='text' name='verify' required='required' />
<img style='cursor:pointer' title='刷新验证码' src='{:U("Index/verify")}' id='verifyImg' onClick='freshVerify()'/>
<button type='submit'>确定</button>
</form>
thinkphp验证码使用的更多相关文章
- ThinkPHP验证码类
//ThinkPHP验证码类使用$config = array( 'fontSize' => 30, // 验证码字体大小 'length' => 3, // 验证码位数 'useNois ...
- thinkphp验证码(总结之后,效率非常好)
thinkphp验证码(总结之后,效率非常好) 一.总结 1.总结:总结之后,效率非常好,复习的时候也才方便,也能深入到细处,非常方便建立熟悉感和突破使用困境 2.验证码使用中文集或者繁体集设置:这个 ...
- thinkphp验证码不现实多半是bom惹的祸
thinkphp 验证码不现实多半是bom惹的祸,下面是驱除bom的代码: 链接:https://pan.baidu.com/s/1v5gm7n0L7TGyejCmQrMh2g 提取码:x2p5 免费 ...
- ThInkPHP验证码不显示,解决方法汇总
出现ThInkPHP验证码不显示的情况 官方提示如下:如果无法显示验证码,请检查:① PHP是否已经安装GD库支持:② 输出之前是否有任何的输出(尤其是UTF8的BOM头信息输出):(打开验证码文件为 ...
- thinkphp验证码
thinkphp自带验证码 前端页面: <div style="position:absolute;z-index:3;top:160px;left:180px;"> ...
- Thinkphp验证码异步验证第二次及以后验证,验证错误----待解决
今天进行差错时遇到的问题.别人的回答----链接(http://www.thinkphp.cn/topic/28968.html) 3.2.3版本里的check方法会在第一次验证正确后清除SESSIO ...
- thinkphp 验证码的使用
在thinkphp中使用验证码很容易,只要调用thinkphp现有的方法就可以.当然,php的GD库肯定是要开的(就是在php.ini中要加载gd模块). thinkphp 3.2 --------- ...
- Thinkphp 验证码、文件上传
一.验证码 验证码参数 例题:登录时验证下验证码 LoginController.class.php <?php namespace Home\Controller; use Think\Con ...
- thinkphp验证码的使用
thinkphp不仅封装了验证规则 还封装了验证码 文件的位置是ThinkPHP\Library\Think\Verify.class.php 下面简单的说一下如何使用 我们现在控制器里新建一个方法 ...
随机推荐
- Initialization of deep networks
Initialization of deep networks 24 Feb 2015Gustav Larsson As we all know, the solution to a non-conv ...
- Objective-C 之优雅的命名(转)
There are only two hard things in Computer Science: cache invalidation and naming things. 在计算机科学中只有两 ...
- 关于thinkphp 开发的网站部署问题
公司一个网站用thinkphp 开发的,由wamp环境移植到lamp环境 出现错误.提示无法生成缓存文件. 原因是thinkphp 的一些目录需要重新生成,所以将一个新的thinkphp 核心包应用后 ...
- php设置cookie,在js中如何获取
在php中设置cookie. $email="abc@163.com"; setcookie("y_email",$email,time()+3600,&quo ...
- Ubuntu 14.04.2 x64 安装tomcat服务器傻瓜教程
序:安装tomcat服务器之前有一堆的准备工作,比如JDK安装. 一.JDK 7 下载及安装 1.下载JDK文件 X86 代表i386,i486系列, 是为32位操作系统所使用的包.X64是64位操作 ...
- 读<你必须知道的.NET>IL指令笔记
IL指令笔记: 1.newObj和initObj MSDN解释:newObj用于分配和初始化对象,而initObj用户初始化值类型 newObj解释: (1):从托管堆分配指定类型所需要的全部内存空间 ...
- 繁华模拟赛 Vincent的城堡
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- 繁华模拟赛 Evensgn剪树枝
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- Linux下读取默认MAC地址
导读MAC(Media Access Control,介质访问控制)计算机通过它来定义并识别网络设备的位置.在嵌入式linux学习中不可避免也会遇到MAC,本文主要描述了如何通过操作OTP来读取嵌入式 ...
- UIImageView 动画 / UIImage 方向
UIImage 方向 UIImage imageOrientation是相对当前屏幕的横竖屏来判断方向 如果本身是横屏, 照片也是横屏的话, 方向是正方向 BOOL b1 = (originalIma ...