首页 > 后端开发 > php教程 > php写的一个验证码

php写的一个验证码

WBOY
发布: 2016-07-25 09:07:13
原创
1016 人浏览过
  1. session_start();
  2. $image = imagecreatetruecolor(58,22);
  3. $color_Background = imagecolorallocate($image,255,255,255);
  4. imagefill($image,0,0,$color_Background);
  5. $key = array(
  6. ‘0′,’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9′,
  7. ‘a’,'b’,'c’,'d’,'e’,'f’,'g’,'h’,'i’,'j’,'k’,'l’,'m’,'n’,'o’,'p’,'q’,'r’,’s’,'t’,'u’,'v’,'w’,'x’,'y’,'z’,
  8. ‘A’,'B’,'C’,'D’,'E’,'F’,'G’,'H’,'I’,'J’,'K’,'L’,'M’,'N’,'O’,'P’,'Q’,'R’,'S’,'T’,'U’,'V’,'W’,'X’,'Y’,'Z’);
  9. $string = null;
  10. $char_X = 6;
  11. $char_Y = 0;
  12. for($i=0;$i{
  13. $char_Y = mt_rand(0,5);
  14. $char = $key[mt_rand(0,61)];
  15. $string .= $char;
  16. $color_Char = imagecolorallocate($image,mt_rand(0,230),mt_rand(0,230),mt_rand(0,230));
  17. imagechar($image,5,$char_X,$char_Y,$char,$color_Char);
  18. $char_X = $char_X + mt_rand(8,15);
  19. }
  20. $line_X1 = 0;
  21. $line_Y1 = 0;
  22. $line_X2 = 0;
  23. $line_Y2 = 0;
  24. for($i=0;$i
  25. {
  26. $line_X1 = mt_rand(0,58);
  27. $line_Y1 = mt_rand(0,22);
  28. $line_X2 = mt_rand(0,58);
  29. $line_Y2 = mt_rand(0,22);
  30. $line_X1 = $line_X1;
  31. $line_Y1 = $line_Y1;
  32. $line_X2 = $line_X1 + mt_rand(1,8);
  33. $line_Y2 = $line_Y1 + mt_rand(1,8);
  34. $color_Line = imagecolorallocate($image,mt_rand(0,230),mt_rand(0,230),mt_rand(0,230));
  35. imageline($image,$line_X1,$line_Y1,$line_X2,$line_Y2,$color_Line);
  36. }
  37. $_SESSION['seccode'] = $string;
  38. @header(“Expires: -1″);
  39. @header(“Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0″, FALSE);
  40. @header(“Pragma: no-cache”);
  41. header(‘Content-Type: image/jpeg’);
  42. imagepng($image);
  43. imagedestroy($image);
  44. ?>
复制代码


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板