php寫的一個驗證碼

WBOY
發布: 2016-07-25 09:07:13
原創
993 人瀏覽過
  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<4;$i++)
  13. {
  14. $char_Y = mt_rand(0,5);
  15. $char = $key[mt_rand(0,61)];
  16. $string .= $char;
  17. $color_Char = imagecolorallocate($image,mt_rand(0,230),mt_rand(0,230),mt_rand(0,230));
  18. imagechar($image,5,$char_X,$char_Y,$char,$color_Char);
  19. $char_X = $char_X + mt_rand(8,15);
  20. }
  21. $line_X1 = 0;
  22. $line_Y1 = 0;
  23. $line_X2 = 0;
  24. $line_Y2 = 0;
  25. for($i=0;$i
  26. {
  27. $line_X1 = mt_rand(0,58);
  28. $line_Y1 = mt_rand(0,22);
  29. $line_X2 = mt_rand(0,58);
  30. $line_Y2 = mt_rand(0,22);
  31. $line_X1 = $line_X1;
  32. $line_Y1 = $line_Y1;
  33. $line_X2 = $line_X1 + mt_rand(1,8);
  34. $line_Y2 = $line_Y1 + mt_rand(1,8);
  35. $color_Line = imagecolorallocate($image,mt_rand(0,230),mt_rand(0,230),mt_rand(0,230));
  36. imageline($image,$line_X1,$line_Y1,$line_X2,$line_Y2,$color_Line);
  37. }
  38. $_SESSION['seccode'] = $string;
  39. @header(“Expires: -1″);
  40. @header(“Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0″, FALSE);
  41. @header(“Pragma: no-cache”);
  42. header(‘Content-Type: image/jpeg’);
  43. imagepng($image);
  44. imagedestroy($image);
  45. ?>
复制代码


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板