生成简单的php验证码
2014-03-04 10:36
274 查看
之前发表过,但是上面只是一个截图,不便于大家复制和使用,所以在这重新发表一遍。
<?php
//生成验证码图片
Header("Content-type: image/JPEG");
srand((double)microtime()*1000000);
$im = imagecreate(62,25);
$grey = imagecolorallocate($im, 255,255,255); //背景颜色
$white = imagecolorallocate($im,mt_rand(0,200),mt_rand(0,200),mt_rand(0,200)); //文字颜色
$black = imagecolorallocate($im, 0,0,0);
imagerectangle($im,0,0,61,24,$black);
//imagefill($im,60,23,$grey);
echo $authnum;
$authnum=rand(1000,9999);
//将四位整数验证码绘入图片
imagestring($im,5,20,5, $_SESSION['check'], $white);
for($i=0;$i<500;$i++) //加入干扰象素
{
$randcolor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
imagejpeg($im);
imagedestroy($im);
?>
<?php
//生成验证码图片
Header("Content-type: image/JPEG");
srand((double)microtime()*1000000);
$im = imagecreate(62,25);
$grey = imagecolorallocate($im, 255,255,255); //背景颜色
$white = imagecolorallocate($im,mt_rand(0,200),mt_rand(0,200),mt_rand(0,200)); //文字颜色
$black = imagecolorallocate($im, 0,0,0);
imagerectangle($im,0,0,61,24,$black);
//imagefill($im,60,23,$grey);
echo $authnum;
$authnum=rand(1000,9999);
//将四位整数验证码绘入图片
imagestring($im,5,20,5, $_SESSION['check'], $white);
for($i=0;$i<500;$i++) //加入干扰象素
{
$randcolor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
imagejpeg($im);
imagedestroy($im);
?>
相关文章推荐
- PHP生成一个简单的验证码图片
- PHP生成验证码的简单代码示例
- PHP 用session与gd库实现简单验证码生成与验证的类方法
- 简单的php验证码生成
- 基于PHP生成简单的验证码
- php简单生成验证码图片
- PHP生成制作验证码的简单实例
- 基于PHP生成简单的验证码
- PHP 用session与gd库实现简单验证码生成与验证的类
- 简单的PHP验证码生成
- PHP 用session与gd库实现简单验证码生成与验证的类
- PHP生成制作验证码的简单实例
- PHP生成可点击刷新的验证码简单示例
- PHP生成简单计算的验证码,模仿CSDN
- 一个简单的PHP生成验证码
- PHP生成可点击刷新的验证码简单示例
- PHP 用session与gd库实现简单验证码生成与验证的类方法
- 一个简单的php图形验证码生成程序
- 一个简单的php图形验证码生成程序
- php基础之gd图像生成、缩放、logo水印和简单验证码实现