Home  >  Article  >  Backend Development  >  php digital verification code

php digital verification code

WBOY
WBOYOriginal
2016-07-25 09:09:01799browse
  1. session_start();
  2. //Generate verification code image
  3. Header("Content-type: image/PNG");
  4. srand((double)microtime()*1000000) ;
  5. $im = imagecreate(62,20);
  6. $black = ImageColorAllocate($im, 69,120,239);
  7. $white = ImageColorAllocate($im, 0,0,0);
  8. $gray = ImageColorAllocate( $im, 200,200,200);
  9. imagefill($im,68,30,$gray);
  10. while(($authnum=rand()%100000)<10000);
  11. //Change the five-digit integer verification code Draw the image
  12. imagestring($im, 5, 10, 3, $authnum, $white);
  13. for($i=0;$i<200;$i++) //Add interference pixels
  14. {
  15. $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
  16. imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
  17. }
  18. ImagePNG($im);
  19. ImageDestroy($im);
  20. $_SESSION['SESSION_VALIDATE_CODE'] = $authnum.'';
  21. ?>
  22. $txt="memory";
  23. $im = imagecreatetruecolor(400,30);
  24. $white = ImageColorAllocate($im, 255,255,255);
  25. $black = ImageColorAllocate($im, 0,0,0);
  26. // Replace path by your own font path
  27. imagestring($ im,1,10,10,$txt,$black);
  28. //imagettftext($im, 20, 0, 10, 20, $black, "font.ttf","Testing...");
  29. header ("Content-type:image/jpeg");
  30. imagejpeg($im);
  31. // imagedestroy($im);
Copy code


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