composer require gregwar/captcha:1.*
// 生成验证码图片
$builder = new CaptchaBuilder();
// 可以设置图片宽高及字体s
$builder->build();
// 获取验证码的内容
$phrase = $builder->getPhrase();
// 把内容存入
session(['code' => $phrase]);
// 生成图片
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type:image/jpeg");
$builder->output();
<a href="javascript:void(0)">
![]({{ url('captcha') }})
</a>
<script>
$('#captcha').click(function () {
var url = $(this).attr('src') + '?' + Math.random();
console.log(url);
$(this).attr('src', url);
});
</script>
网友评论