php的配置文件php.ini,搜索extension=php_gd2.dll,去掉前面的分号即可;
1.在模块类中增加一个 verify 方法来用于显示验证码
Public function verify(){
// 导入Image类库
import("ORG.Util.Image");
Image::buildImageVerify();
}
2.表单中使用验证码
<input type="text" name="verify">
<img id="verifyImg" src="__URL__/verify" onClick="changeVerify()" id="code26227">
<script language="JavaScript">
function changeVerify(){
var timenow = new Date().getTime();
document.getElementById('verifyImg').src='__URL__/verify/'+timenow;
}
</script>
4.验证码验证
if($_SESSION['verify'] != md5($_POST['verify'])) {
$this->error('验证码错误!');
}