php生成验证码图片
0:效果图

1:index.php用来生成验证码图片
<?php
session_start();
header ('Content-Type: image/png');
$image=imagecreatetruecolor(100, 30);
//背景颜色为白色
$color=imagecolorallocate($image, 255, 255, 255);
imagefill($image, 20, 20, $color);
// for($i=0;$i<4;$i++){
// $font=6;
// $x=rand(5,10)+$i*100/4;
// $y=rand(8, 15);
// $string=rand(0, 9);
// $color=imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
// imagestring($image, $font, $x, $y, $string, $color);
// }
$code='';
for($i=0;$i<4;$i++){
$fontSize=8;
$x=rand(5,10)+$i*100/4;
$y=rand(5, 15);
$data='abcdefghijklmnopqrstuvwxyz123456789';
$string=substr($data,rand(0, strlen($data)),1);
$code.=$string;
$color=imagecolorallocate($image,rand(0,120), rand(0,120), rand(0,120));
imagestring($image, $fontSize, $x, $y, $string, $color);
}
$_SESSION['code']=$code;//存储在session里
for($i=0;$i<200;$i++){
$pointColor=imagecolorallocate($image, rand(100, 255), rand(100, 255), rand(100, 255));
imagesetpixel($image, rand(0, 100), rand(0, 30), $pointColor);
}
for($i=0;$i<2;$i++){
$linePoint=imagecolorallocate($image, rand(150, 255), rand(150, 255), rand(150, 255));
imageline($image, rand(10, 50), rand(10, 20), rand(80,90), rand(15, 25), $linePoint);
}
imagepng($image);
imagedestroy($image);
?>
2:form.php前端页面.用于输入验证码并验证
<?php
if(isset($_REQUEST['code'])){
session_start();
if($_REQUEST['code']==$_SESSION['code']){
echo "<font color='red'>输入正确</font>";
}else{
echo "<font color='red'>输入错误</font>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta chartset="UTF-8" />
<style type="text/css" rel="stylesheet">
a{
text-decoration:none;
font-size:30px;
color:blue;
}
a:hover{
text-decoration:underline;
}
</style>
</head>
<body>
<form action="form.php" method="get">
验证码: <img id="img" src="index.php?" onclick="changeCode()"/>
<a href="javascript:void(0)" onclick="changeCode()">看不清?</a> <br />
请输入验证码: <input name="code" /><br />
<input type="submit" value="提交" />
</form>
</body>
<script type="text/javascript"> function changeCode(){
var img=document.getElementById('img');
//img.src='index.php?r='+Math.random();
img.setAttribute('src','index.php?r='+Math.random());
}
</script>
</html>
php生成验证码图片的更多相关文章
- java web学习总结(九) -------------------通过Servlet生成验证码图片
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- JavaWeb---总结(九)通过Servlet生成验证码图片
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下: 创建一个DrawImage Servlet,用来生成验证码图片 1 package gacl. ...
- Java 生成验证码图片
生成验证码图片并对提交的输入进行验证 // HttpServletResponse常见应用——生成验证码 // 利用BufferedImage类生产随机图片 public static final i ...
- javaweb学习总结(九)—— 通过Servlet生成验证码图片
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- 012. asp.net生成验证码图片(汉字示例/字母+数字)
protected void Page_Load(object sender, EventArgs e) { //生成验证码图片的基本步骤 string checkCode = "新年快乐& ...
- J2EE如何生成验证码图片和点击刷新验证码
验证码图片生成步骤 创建BufferedImage对象. 获取BufferedImage的画笔,即调用getGraphics()方法获取Graphics对象. 调用Graphics对象的setColo ...
- java web 学习九(通过servlet生成验证码图片)
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- java web,生成验证码图片的技术
偶然知道原来有些网站的验证码图片都是随机生成的,后来听人讲了一下,就做了这个小例子 生成图片,绘制背景,数字,干扰线用到了java.awt包,主要使用BufferedImage来生成图片,然后使用Gr ...
- 通过Servlet生成验证码图片
原文出自:http://www.cnblogs.com/xdp-gacl/p/3798190.html 一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类, ...
随机推荐
- SharePoint 2013版本功能对比介绍
转:http://www.fengfly.com/plus/view-213720-1.html 在SharePoint使用中,经常纠结于版本问题,SharePoint 2013主要有免费的Found ...
- Alexander Grothendieck去世了
Alexander Grothendieck (German: [ˈɡroːtn̩diːk]; French: [ɡʁɔtɛndik]; 28 March 1928 – 13 November 201 ...
- Servlet3.0学习总结(三)——基于Servlet3.0的文件上传
在Servlet2.5中,我们要实现文件上传功能时,一般都需要借助第三方开源组件,例如Apache的commons-fileupload组件,在Servlet3.0中提供了对文件上传的原生支持,我们不 ...
- 关于HTTP返回码301、302区别与SEO
301(永久移动)请求的网页已永久移动到新位置.服务器返回此响应时,会自动将请求者转到新位置.您应使用此代码告诉搜索引擎Spider某个网页或网站已永久移动到新位置.建议在URL规范化的时候采用301 ...
- [liu yanling]规范软件测试流程
测试计划 做任何事情都会有输入输出,对于测试过程我们可以把输入理解为测试计划.测试环境准备.测试工具的选择等等,输出可以理解为测试结果.测试用例设计即可以理解为以测试计划为输入的输出,也可以理解为以测 ...
- SVN记住用户名和密码后如何修改
今天遇到一个SVN检出代码用户验证问题.由于自己最近参与了好几个项目,一时间忙不过来.所以希望跟着自己的试用期的同事帮我测试一下刚修改完成的新功能是否有问题.但是该同事没有项目中权限,正好今天恰逢星期 ...
- 五指cms标签说明汇总
1.栏目列表标签 只有一级导航: {wz:content action="category" cid="0" pagesize="100" ...
- sensor的skipping and binning 模式
关于sensor的缩放存在两种模式 binning mode 和skip mode skipping mode 就是把想要的数据采集上来 把其余的数据扔掉 如下所示 column skip 2 row ...
- storm-starter项目概述
storm-starter项目包含使用storm的各种各样的例子.项目托管在GitHub上面,其网址为: http://github.com/nathanmarz/storm-starter stor ...
- nyoj 1022 最少步数【优先队列+广搜】
最少步数 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 这有一个迷宫,有0~8行和0~8列: 1,1,1,1,1,1,1,1,1 1,0,0,1,0,0,1,0,1 ...