Home >Backend Development >PHP Tutorial >PHP generates graphic verification code (mixed uppercase and lowercase letters and numbers)

PHP generates graphic verification code (mixed uppercase and lowercase letters and numbers)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:45:461382browse
  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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn