php 验证码
来源:互联网 发布:淘宝哪家零食店好 编辑:程序博客网 时间:2024/05/29 18:12
<?php
header("Content-Type:image/png");
//开启session
session_start();
//随机4个数字
$code = "";
$arr = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";
for ($i = 0; $i < 4; $i++) {
$code .= $arr[rand(0, strlen($arr)-1)];
}
//设置入session中,方便比对
$_SESSION["validcode"] = $code;
//开始绘图
$width = 100;
$height = 25;
$img = imagecreatetruecolor($width,$height);
//填充背景色
$backcolor = imagecolorallocate($img,0,0,0);
imagefill($img,0,0,$backcolor);
//获取随机较深颜色
for($i=0;$i<10;$i++){
$textcolor = imagecolorallocate($img,rand(50,180),rand(50,180),rand(50,180));
imagechar($img,5,7+$i*25,3,$code[$i],$textcolor);
}
for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img, rand(1,100) , rand(2,18) , $randcolor);
}
//显示图片
imagepng($img);
//销毁图片
imagedestroy($img);
?>
header("Content-Type:image/png");
//开启session
session_start();
//随机4个数字
$code = "";
$arr = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";
for ($i = 0; $i < 4; $i++) {
$code .= $arr[rand(0, strlen($arr)-1)];
}
//设置入session中,方便比对
$_SESSION["validcode"] = $code;
//开始绘图
$width = 100;
$height = 25;
$img = imagecreatetruecolor($width,$height);
//填充背景色
$backcolor = imagecolorallocate($img,0,0,0);
imagefill($img,0,0,$backcolor);
//获取随机较深颜色
for($i=0;$i<10;$i++){
$textcolor = imagecolorallocate($img,rand(50,180),rand(50,180),rand(50,180));
imagechar($img,5,7+$i*25,3,$code[$i],$textcolor);
}
for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img, rand(1,100) , rand(2,18) , $randcolor);
}
//显示图片
imagepng($img);
//销毁图片
imagedestroy($img);
?>
0 0
- php图形验证码
- php 验证码
- PHP 验证码
- PHP图片验证码
- php验证码类
- php实现验证码
- PHP实现验证码
- PHP实现验证码
- PHP生成验证码
- PHP验证码
- php验证码类
- PHP 生成验证码
- php 验证码
- php 图片验证码
- php 验证码控件
- php 验证码总结
- PHP验证码生成
- PHP生成验证码
- 解决所有MyEclipse中文乱码问题
- zabbix mysql 迁移总结
- 进程与线程的差别
- C语言细节:va_list,...,##, #等
- Ajax学习(3)Jackson使用
- php 验证码
- 十个利用矩阵乘法解决的经典题目
- c/c++程序的编译过程资料汇总
- 字节对齐
- 如何在matlab中使用java
- 为什么我不推荐大家去外包公司
- OpenGl的glMatrixMode()函数理解
- Ubuntu 下mysql卸载与安装
- 阿里天池大数据