You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
847 B

3 years ago
  1. <?php
  2. session_start();
  3. //生成验证码图片
  4. Header("Content-type: image/PNG");
  5. $im = imagecreate(44,18); // 画一张指定宽高的图片
  6. $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色
  7. imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中
  8. $vcodes = "";
  9. srand((double)microtime()*1000000);
  10. //生成4位数字
  11. for($i=0;$i<4;$i++){
  12. $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色
  13. $authnum=rand(1,9);
  14. $vcodes.=$authnum;
  15. imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
  16. }
  17. $_SESSION['v_code'] = $vcodes;
  18. for($i=0;$i<200;$i++) //加入干扰象素
  19. {
  20. $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
  21. imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数
  22. }
  23. ImagePNG($im);
  24. ImageDestroy($im);
  25. ?>