Vendor('Vcode.Vcode', '', '.class.php');
$config = array("width" => 100, "height" => 36, "count" => 4, "str" => 2); //配置
$vcode = new \Vcode($config);
$vcode->getCode(); //获取验证码
$vcode->getImg(); //输出图片
exit;验证码图片
JS通过后缀加随机数Math.random()来刷新验证码
function changeCode(obj) {
obj.attr("src", '__APP__/code/?' + Math.random());
}检测验证码是否输入正确
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["sucaihuo_code"]) {
echo "1";
} else {
echo "-1";
}
}1、执行速度快。2、具有很好的开放性和可扩展性。3、PHP支持多种主流与非主流的数据库。4、面向对象编程:PHP提供了类和对象。5、版本更新速度快。6、具有丰富的功能。7、可伸缩性。8、功能全面,包括图形处理、编码与解码、压缩文件处理、xml解析等。