php代码实现随机动态验证码
2020-07-18 04:44
573 查看
设置字母混合效果和干扰元素
通过SESSION存储验证信息
session_start(); $width = 150; $height = 40; $image = imagecreatetruecolor($width, $height);$bgcolor = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $bgcolor); $cap_code = ""; for ($i = 0; $i < 4; $i++) { $fontsize = 30; $fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120)); $data = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM123456789'; $fontcontent = substr($data, rand(0, strlen($data)), 1); $cap_code .= $fontcontent; $x = ($i * 150 / 4) + rand(5, 10); $y = rand(5, 10); imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);} $_SESSION['code'] = $cap_code; for ($i = 0; $i < 300; $i++) { $inputcolor = imagecolorallocate($image, rand(50, 200), rand(20, 200), rand(50, 200)); imagesetpixel($image, rand(1, 149), rand(1, 39), $inputcolor); } for ($i = 0; $i < 4; $i++) { $linecolor = imagecolorallocate($image, rand(20, 220), rand(20, 220), rand(20, 220)); imageline($image, rand(1, 149), rand(1, 39), rand(1, 299), rand(1, 149), $linecolor); } header('Content-Type:image/png'); imagepng($image);
使用验证码, 验证用户的提交操作
还有一个css小特效哦
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>展现你实力的时候到啦</title> <style> #myDIV{ width:200px; height:65px; background:red; animation:mymove 5s infinite; -webkit-animation:mymove 5s infinite; } @keyframes mymove { from {background-color:green;} to {background-color:yellow;}} @-webkit-keyframes mymove { from {background-color:yellow;} to {background-color:green;} } </style> </head> <body> <div id="myDIV"> <?php header("Content-Type: text/html;charset=utf-8"); if (isset($_REQUEST['code'])){ session_start(); if ($_REQUEST['code'] == $_SESSION['code']){ echo "对于如此优秀的你来说考试不就像吹牛皮一样说破就破吗?"; }else{ echo "你是猪吗?"; } exit();} ?> </div> <form> <p>验证码:<img src="sxj.php" onClick="this.src='sxj.php?nocache='+Math.random()" style="cursor:hand" alt="点击换一张"/>点击图片可更换验证码</p> <p>请输入图片中的内容:<input type="text" name="code" value=""/></p> <p><input type="submit" width="20px" height=19px value="提交"></input></p> </form> </body> </html>
相关文章推荐
- 【代码实现】PHP生成各种随机验证码
- 【代码实现】PHP生成各种随机验证码
- 【代码】PHP 生成GIF动画实现动态图片验证码
- php实现动态随机验证码机制(CAPTCHA)
- (转)PHP PEAR中用Text_Password轻松实现随机密码以及图形验证码
- php 生成随机验证码图片代码
- php动态实现表格跨行跨列实现代码
- PHP 反射机制实现动态代理的代码
- vue实现随机验证码功能的实例代码
- php 数组动态添加实现代码(最土团购系统的价格排序)
- PHP生成随机用户名和密码的实现代码
- php生成4位数字验证码的实现代码
- iOS动态验证码实现代码
- PHP实现动态执行代码的方法
- php实现随机6位验证码
- php 随机排序广告的实现代码
- PHP生成随机用户名和密码的实现代码
- 一个简单的PHP验证码实现代码
- PHP随机生成N个汉字的实现方法(含代码)
- php实现概率性随机抽奖代码