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">
验证码: &nbsp;<img id="img" src="index.php?" onclick="changeCode()"/>
<a href="javascript:void(0)" onclick="changeCode()">看不清?</a>&nbsp;<br />
请输入验证码:&nbsp;<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生成验证码图片的更多相关文章

  1. java web学习总结(九) -------------------通过Servlet生成验证码图片

    一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:

  2. JavaWeb---总结(九)通过Servlet生成验证码图片

    一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下: 创建一个DrawImage Servlet,用来生成验证码图片  1 package gacl. ...

  3. Java 生成验证码图片

    生成验证码图片并对提交的输入进行验证 // HttpServletResponse常见应用——生成验证码 // 利用BufferedImage类生产随机图片 public static final i ...

  4. javaweb学习总结(九)—— 通过Servlet生成验证码图片

    一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:

  5. 012. asp.net生成验证码图片(汉字示例/字母+数字)

    protected void Page_Load(object sender, EventArgs e) { //生成验证码图片的基本步骤 string checkCode = "新年快乐& ...

  6. J2EE如何生成验证码图片和点击刷新验证码

    验证码图片生成步骤 创建BufferedImage对象. 获取BufferedImage的画笔,即调用getGraphics()方法获取Graphics对象. 调用Graphics对象的setColo ...

  7. java web 学习九(通过servlet生成验证码图片)

    一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:

  8. java web,生成验证码图片的技术

    偶然知道原来有些网站的验证码图片都是随机生成的,后来听人讲了一下,就做了这个小例子 生成图片,绘制背景,数字,干扰线用到了java.awt包,主要使用BufferedImage来生成图片,然后使用Gr ...

  9. 通过Servlet生成验证码图片

    原文出自:http://www.cnblogs.com/xdp-gacl/p/3798190.html 一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类, ...

随机推荐

  1. angular.extend

    function f1() {} var f2 = angular.extend(f1, { active: false, toggle: function() { this.active = !th ...

  2. ☀【CSS3】box-sizing

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  3. Java问题汇集(1)

    1.javax.el.PropertyNotFoundException: Property 'Price' not found on type pet.petshop.dto.WareDto 简答: ...

  4. asp.net 使用 MongoDB 初体验

    首先:驱动 如果asp.net 想使用MongoDB,.net没有自带的链接类.得用第三方或官方的链接类. 当然有很多种驱动,我就不一一介绍了. 今天我就介绍一个我比较常用的驱动-----MongoD ...

  5. 【CSS】Beginner6:Border

    1.border-style:solid实线,dashed虚线,double双线,dotted点状,groove凹槽,ridge垄状,inset,outset 2.border0-width:bord ...

  6. 各种sensor名称统计

    gyroscopes 陀螺仪accelerometers 加速度计magnetometers 磁力计barometric pressure 气压remote pressure sensing 远程压力 ...

  7. boj1267 Infinite’s Cave 树形dp + 背包

    题目链接:http://acm.bupt.edu.cn/onlinejudge/newoj/showProblem/show_problem.php?problem_id=1267         / ...

  8. Configuring Active Directory Federation Services 2.0 (配置 adfs 2.0) -摘自网络

    Active Directory Federation Services (AD FS) 2.0 makes it possible to deploy a federation server and ...

  9. WPF的MVVM模式

    Model->數據模型View->視圖View-Model->連接數據模型和視圖

  10. Laravel教程:laravel 4安装及入门

    一.安装Composer首先你需要安装Composer,Composer是PHP依赖管理工具,Laravel框架就是使用 Composer 执行安装和依赖管理. 注:(1)若安装Composer出错, ...