宝哥软件园

PHP实现字母数字验证码功能

编辑:宝哥软件园 来源:互联网 时间:2021-08-21

一个简单的PHP实现字母数字验证码,支持自定义验证码,验证码图片,宽度,高度,数字,背景图片等

验证码调用地址:应用家庭控制器 codecontroller.class.php。

供应商(' Vcode。Vcode ','', class . PHP ');$config=array('width'=100,' height'=36,' count'=4,' str '=2);//configure $ Vcode=new Vcode($ config);$ vcode-GetCode();//获取验证码$ vcode-getig();//输出图片退出;验证码图片

img src=' http : _ _ app _ _/code/' id=' code ' onclick=' change code($(' # code '))'/js通过后缀加上随机数Math.random()刷新验证码

函数changeCode(obj) { obj.attr('src ',' __APP__/code/?'math . random());}检查验证码输入是否正确

input type=' text ' id=' input _ code ' class=' input '/input type=' button ' value=' submit ' class=' BTN ' onclick=' check code()'/function check code(){ $。post ('_ _ app _ _/code/check ',{code: $ ('# input _ code ')。val ()},函数(数据){if(数据=' 1') {alert('验证码正确!');} else {alert('错误的验证码!');}} },' json') }PHP将PHP验证通过的参数代码与当前会话中存储的验证代码进行比较,如果正确返回1,错误的将为-1。

公共函数check(){ $ code=I(' post . code ');if(strtolow($ code)=$ _ SESSION[' sucaihuo _ code ']){ echo ' 1 ';} else { echo '-1 ';}}摘要

以上是PHP实现字母数字验证码的介绍,对大家有帮助。如果你有任何问题,请给我留言,边肖会及时回复你。非常感谢您对我们网站的支持!如果你觉得这篇文章对你有帮助,请转载,请注明出处,谢谢!

更多资讯
游戏推荐
更多+