parent
8785e2ce50
commit
36251d5230
|
@ -9,16 +9,16 @@ $bgcolor = imagecolorallocate($image, 255, 255, 255); //验证码颜色RGB为(25
|
|||
imagefill($image, 0, 0, $bgcolor); //区域填充
|
||||
|
||||
$cap_code = "";
|
||||
for($i=0;$i<4;$i++){
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$fontsize = 12; //设置字体大小
|
||||
$fontcolor = imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
|
||||
$fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
|
||||
//数字越大,颜色越浅,这里是深颜色0-120
|
||||
$data = 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890'; //添加字符串
|
||||
$fontcontent = substr($data, rand(0,strlen($data)),1); //去除值,字符串截取方法
|
||||
$cap_code.=$fontcontent; //.=连续定义变量
|
||||
$fontcontent = substr($data, rand(0, strlen($data)), 1); //去除值,字符串截取方法
|
||||
$cap_code .= $fontcontent; //.=连续定义变量
|
||||
|
||||
$x = ($i*150/4)+rand(5,10);
|
||||
$y = rand(5,10);
|
||||
$x = ($i * 150 / 4) + rand(5, 10);
|
||||
$y = rand(5, 10);
|
||||
//设置坐标
|
||||
|
||||
imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
|
||||
|
@ -27,20 +27,19 @@ for($i=0;$i<4;$i++){
|
|||
$_SESSION['code'] = $cap_code; //存到session
|
||||
|
||||
//设置干扰元素,设置雪花点
|
||||
for($i=0;$i<300;$i++){
|
||||
$inputcolor = imagecolorallocate($image, rand(50,200), rand(20,200), rand(50,200));
|
||||
for ($i = 0; $i < 300; $i++) {
|
||||
$inputcolor = imagecolorallocate($image, rand(50, 200), rand(20, 200), rand(50, 200));
|
||||
//设置颜色,20-200颜色比数字浅,不干扰阅读
|
||||
imagesetpixel($image, rand(1,149), rand(1,39), $inputcolor);
|
||||
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));
|
||||
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);
|
||||
|
||||
imageline($image, rand(1, 149), rand(1, 39), rand(1, 299), rand(1, 149), $linecolor);
|
||||
}
|
||||
|
||||
//因为有些浏览器,访问的content-type会是文本型,所以我们需要设置成图片的格式类型
|
||||
|
|
|
@ -48,7 +48,6 @@ if (isset($_REQUEST['code'])) {
|
|||
</script>';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<form class="form-horizontal" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" onsubmit="return md5_post()">
|
||||
<div class="form-group">
|
||||
|
@ -72,7 +71,6 @@ if (isset($_REQUEST['code'])) {
|
|||
<input class="form-control" type="text" name="code" value="" placeholder="请输入上方4位数验证码 - 注意大小写" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<div class="checkbox">
|
||||
|
@ -88,7 +86,6 @@ if (isset($_REQUEST['code'])) {
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script src="<?php static_cdn(); ?>/public/static/md5.min.js"></script>
|
||||
<script>
|
||||
function md5_post() {
|
||||
|
@ -99,6 +96,5 @@ if (isset($_REQUEST['code'])) {
|
|||
return true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require_once APP_ROOT . '/application/footer.php';
|
||||
|
|
Loading…
Reference in New Issue