yz_img.php 655 B

123456789101112131415161718192021222324252627
  1. <?
  2. session_start();
  3. //生成验证码图片
  4. Header("Content-type: image/PNG");
  5. $im = imagecreate(44,15);
  6. $back = ImageColorAllocate($im, 245,245,245);
  7. imagefill($im,0,0,$back); //背景
  8. srand((double)microtime()*1000000);
  9. //生成4位数字
  10. for($i=0;$i<4;$i++){
  11. $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));
  12. $authnum=rand(1,9);
  13. $vcodes.=$authnum;
  14. imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
  15. }
  16. for($i=0;$i<100;$i++) //加入干扰象素
  17. {
  18. $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
  19. imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
  20. }
  21. ImagePNG($im);
  22. ImageDestroy($im);
  23. $_SESSION['VCODE'] = $vcodes;
  24. ?>