php验证码
2020-12-13 03:33
标签:style blog class code c tar php验证码,搜素材,soscw.com php验证码 标签:style blog class code c tar 原文地址:http://www.cnblogs.com/5huihui/p/3726649.html
session_start();$arr = array(
‘a‘,‘b‘,‘c‘,‘d‘,‘e‘,‘f‘,‘g‘,‘h‘,‘i‘,‘j‘,‘k‘,‘l‘,‘m‘,‘n‘,‘o‘,‘p‘,‘q‘,‘r‘,‘s‘,‘t‘,‘u‘,‘v‘,‘w‘,‘x‘,
‘y‘,‘z‘,‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘
);$rand = "";
for($i=1;$i$i++){ "background-color: rgb(192, 192, 192);">//随机产生4个由不同字母与数字组合成的验证码 $rand
.= $arr[rand(0,count($arr)-1)];
}$_SESSION[‘check_pic‘] = $rand;
"background-color: rgb(192, 192, 192);">//生成图片$im =
"color: rgb(255, 0, 0);">imagecreatetruecolor(100,30);"background-color: rgb(192, 192, 192);">//生成颜色,当第一次调用生成颜色的方法,是生成背景颜色$bg = "color: rgb(255, 0, 0);">imagecolorallocate($im,0,0,0);
"background-color: rgb(192, 192, 192);">//第二次调用这个方法,是可以生成图片上面的文字或其他样式的颜色$te
="color: rgb(255, 0, 0);"> imagecolorallocate($im,255,255,255);
"background-color: rgb(192, 192, 192);">//在图片上面生成文字"color: rgb(255, 0, 0);">imagestring($im,rand(1,5),rand(3,70),rand(3,15),$rand,$te);
"background-color: rgb(192, 192, 192);">//要把php当成图片输出,必须给文件一个头申明"color: rgb(255, 0, 0);">ob_clean();"color: rgb(255, 0, 0);">header("Content-type:image/jpeg");
"background-color: rgb(192, 192, 192);">//最终生成图片"color: rgb(255, 0, 0);">imagejpeg($im);
?>
"background-color: rgb(255, 102, 0);">imagecreatetruecolor(宽,高); 图片宽高
"background-color: rgb(255, 102, 0);">imagecolorallocate(图片,红,绿,蓝) "line-height: 1.5;">调用(三原色)生成颜色的方法,是生成背景颜色
"background-color: rgb(255, 102, 0);">imagestring"line-height: 1.5;">(图片,字体大小,字所在的x轴,"line-height: 1.5;">字所在的y轴,要显示的验证码,字体颜色"line-height: 1.5;">)
"background-color: rgb(255, 102, 0);">header 要把php当成图片输出,必须给文件一个头申明
"background-color: rgb(255, 102, 0);">imagejpeg(图片) 生成图片
下一篇:JS对象/数组/识别对象数组