PHP原创验证码

PHP原创验证码

今天素材圈给朋友们分享一个简单的验证码,支持自定义验证码、验证码图片、宽度、高度、个数、背景图片等

淘建站为您提供更多_Thinkphp_验证码_code,在此特别感谢您对我们的支持与厚爱!

查看演示

演示不了,点击反馈

加入收藏

下载 226 次

打赏作者

觉得不错,可打赏下作者

下载资源

免费共享

特别说明:本站资源来自网友发布分享,仅供学习与参考,请勿用于商业用途,若有侵权请联系删除(272966172@qq.com)。
分类:PHP功能模块 > 插件 难易程度:初级

验证码调用地址:Application\Home\Controller\CodeController.class.php

Vendor('Vcode.Vcode', '', '.class.php');
$config = array("width" => 100, "height" => 36, "count" => 4, "str" => 2); //配置
$vcode = new \Vcode($config);
$vcode->getCode(); //获取验证码
$vcode->getImg(); //输出图片
exit;

验证码图片

<img src="__APP__/code/" id="code" onclick="changeCode($('#code'))"/>

JS通过后缀加随机数Math.random()来刷新验证码

function changeCode(obj) {
   obj.attr("src", '__APP__/code/?' + Math.random());
}

检测验证码是否输入正确

<input type="text" id="input_code" class="input"/>
<input type="button" value="提交" class="btn" onclick="checkCode()"/>
function checkCode() {
    $.post("__APP__/Code/check", {code: $("#input_code").val()}, function(data) {
        if (data == '1') {
            alert("验证码正确!");
        } else {
            alert("验证码错误!");
        }
    }, "json")
}

PHP验证传过来的参数code和当前session存储的验证码进行比较,若是正确返回1,错误则-1

public function check() {
        $code = I('post.code');
        if (strtolower($code) == $_SESSION["sucaiq_code"]) {
            echo "1";
        } else {
            echo "-1";
        }
}

声明:本资料由淘建站会员提供,如转载注明来源,资料来源淘建站免费素材库:https://www.taojz.cn/mokuai/533.html
PHP原创验证码 希望对你有帮助,感谢您的支持!
留言(0)
头像
 阿里云限量代金券,戳我领取
1 2