PHP验证码程序

it2022-05-08  10

效果图:

 点击验证码图片可更换另一个:

login.php 如何调用呢? 假设生成验证码的文件是 yz.php:

调用:<img src="http://blog.163.com/skill_sun/blog/yz.php" alt="看不清?点击换一张" οnclick="this.src=this.src"/>

yz.php 文件:

--------------------------------------------------------------------------------------------------------------------------

<?php  session_start();

  //生成验证码图  Header("Content-type: image/PNG");  //长与宽  $im = imagecreate(44,18);  // 设置背景色:  $back = ImageColorAllocate($im, 245,245,245);  // 填充背景色:  imagefill($im,0,0,$back);

  srand((double)microtime()*1000000);  //生成4位数字  for($i=0;$i<4;$i++){    $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));    $authnum=rand(1,9);    $vcodes.=$authnum;    imagestring($im, 5, 2+$i*10, 1, $authnum, $font);  }

  //加入干扰象素  for($i=0;$i<100;$i++){   $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));   imagesetpixel($im, rand()p , rand()0 , $randcolor);  }     ImagePNG($im);  ImageDestroy($im);

  // 将四位的验证码保存在 SESSION 里,登录时调用对比  $_SESSION['VCODE'] = $vcodes;  ?>

转载于:https://www.cnblogs.com/Jerry-blog/p/5010283.html

相关资源:基于php实现的验证码小程序

最新回复(0)