码迷,mamicode.com
首页 > Web开发 > 详细

简单的php验证码生成

时间:2015-06-01 16:47:59      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:


	//生成图片
	$width="100";
	$height="50";
	
	//生成一个背景,默认黑色
	$img=imagecreatetruecolor($width, $height);
	
	//生成颜色
	$background=imagecolorallocate($img,200,200,200);
	$white=imagecolorallocate($img,255,255,255);
	$blue=imagecolorallocate($img,0,0,64);
	
	//替换背颜色
	imagefill($img,0,0,$background);
	
	//加入线条
	for ($i=1;$i<=10;$i++){
		$x1=rand(0,100);
		$y1=rand(0,50);
		$x2=rand(0,100);
		$y2=rand(0,50);
		imageline($img,$x1,$y1, $x2, $y2, imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
	}
	
	//加入小点
	for ($i=1;$i<100;$i++){
		imagesetpixel($img, mt_rand(0,100),mt_rand(0, 50), imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
	}
	
	
	//加入验证码
	$str="abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789";
	$code="";
	$count=strlen($str)-1;
	
	for($i=1;$i<=4;$i++){
		$code .= $str[mt_rand(0,$count)];
	}
	imagestring($img,12, 20, 20,$code,$blue);


	//输出图像
	header("content-type:image/png");
	
	imagepng($img);

简单的php验证码生成

标签:

原文地址:http://blog.csdn.net/czhphp/article/details/46311023

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!