验证码, 写字母, PHP">
当前位置:Gxlcms > PHP教程 > PHP生成图形验证码(大小写字母与数字混合)

PHP生成图形验证码(大小写字母与数字混合)

时间:2021-07-01 10:21:17 帮助过:25人阅读

  1. header("content-type:image/png");
  2. $num = $_GET['num'];
  3. $imagewidth=60;
  4. $imageheight=18;
  5. srand(microtime() * 100000);
  6. $numimage = imagecreate($imagewidth,$imageheight);
  7. imagecolorallocate($numimage,183,180,83);
  8. for($i=0;$i $font = mt_rand(3,5);
  9. $x = mt_rand(1,8)+$imagewidth*$i/4;
  10. $y = mt_rand(1,$imageheight/3);
  11. $color=imagecolorallocate($numimage,mt_rand(0,50),mt_rand(0,150),mt_rand(0,255));
  12. imagestring($numimage,$font,$x,$y,$num[$i],$color);
  13. }
  14. imagepng($numimage);
  15. imagedestroy($numimage);
  16. ?>
  17. 调用方法:
  18. session_start();
  19. include_once 'conn/conn.php';
  20. $pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
  21. $num = null;
  22. for($i = 0; $i < 4; $i++) {
  23. $num .= $pattern{mt_rand(0, 61)};
  24. }
  25. ?>
  26. 验证码:

验证码, 写字母, PHP

人气教程排行