php经典实例验证码的生成和使用源码免费下载

php经典实例验证码的生成和使用源码免费下载

php经典实例验证码的生成和使用源码免费下载

淘建站为您提供更多_函数_验证_验证码,在此特别感谢您对我们的支持与厚爱!

查看演示

演示不了,点击反馈

加入收藏

下载 311 次

下载资源

37 积分

特别说明:本站资源来自网友发布分享,仅供学习与参考,请勿用于商业用途,若有侵权请联系删除(272966172@qq.com)。

<html>
	<head>
		<title>验证码的使用<title>
	</head>
	<body>
		<h2>用户登录(验证码的使用)</h2>
		<form action="" method="post">
		账号:<input type="text" name="user"/><br/><br/>
		密码:<input type="password" name="user"/><br/><br/>
		验证:<input type="text" size="6" name="user"/>
				<img src="code.php" onclick="this.src='code.php?id='+Math.random()"/> <br/><br/>
		
		<input type="submit" value="用户登录"/>
		</form>
	</body>
</html>
<?php
//绘制验证码(生成)

$num=4; //验证码的长度
$str = getCode($num,0);// 使用下面的自定义函数,获取需要的验证码值

//1. 创建一个画布、分配颜色
$width=$num*20;//宽度
$height=30;//高度
$im = imagecreatetruecolor($width,$height);//创建一个画布
//定义几个颜色(输出不同颜色的验证码)
$color[] = imagecolorallocate($im,111,0,55);
$color[] = imagecolorallocate($im,0,77,0);
$color[] = imagecolorallocate($im,0,0,160);
$color[] = imagecolorallocate($im,221,111,0);
$color[] = imagecolorallocate($im,220,0,0);
$bg = imagecolorallocate($im,240,240,240);//背景
//2. 开始绘画
 imagefill($im,0,0,$bg);
 imagerectangle($im,0,0,$width-1,$height-1,$color[rand(0,4)]);
  
 //随机添加干扰点
 for($i=0;$i<200;$i++){
	$c = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//随机一个颜色
	imagesetpixel($im,rand(0,$width),rand(0,$height),$c);
 }
 
 //随机添加干扰线
 for($i=0;$i<5;$i++){
	$c = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//随机一个颜色
	imageline($im,rand(0,$width),rand(0,$height),rand(0,$width),rand(0,$height),$c);
 }
 
 //绘制验证码内容(一个一个字符绘制):
 for($i=0;$i<$num;$i++){
	imagettftext($im,18,rand(-40,40),8+(18*$i),24,$color[rand(0,4)],"msyh.ttf",$str[$i]);
 }
//3. 输出图像
header("Content-Type:image/png");//设置响应头信息(注意此函数实行前不可以有输出)
imagepng($im);
//4. 销毁图片(释放内容)
imagedestroy($im);





/**
 * 随机生成一个验证码的内容的函数
 * @param $m :验证码的个数(默认为4)
 * @param $type : 验证码的类型:0:纯数字 1:数字+小写字母  2:数字+大小写字符
 */
function getCode($m=4,$type=0){
	$str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	$t = array(9,35,strlen($str)-1);
	//随机生成验证码所需内容
	$c="";
	for($i=0;$i<$m;$i++){
		$c.=$str[rand(0,$t[$type])];
	}
	return $c;
}

//echo getCode();

声明:本资料由淘建站会员提供,如转载注明来源,资料来源淘建站免费素材库:https://www.taojz.cn/mokuai/946.html
php经典实例验证码的生成和使用源码免费下载 希望对你有帮助,感谢您的支持!
  • PHP安全之数据过滤和验证

    PHP安全之数据过滤和验证

  • PHP通用正则验证类

    PHP通用正则验证类

  • php声音验证码

    php声音验证码

  • PHP生成图片验证码

    PHP生成图片验证码

  • PHP七种不同的个性创意验证码

    PHP七种不同的个性创意验证码

  • PHP检测中文验证码实例演示

    PHP检测中文验证码实例演示

  • 留言(0)
    头像
     阿里云限量代金券,戳我领取
    1 2