Home > Backend Development > PHP Tutorial > PHP generates alphanumeric verification code images

PHP generates alphanumeric verification code images

WBOY
Release: 2016-07-25 08:44:37
Original
1033 people have browsed it

php generates alphanumeric verification code images

  1. header ('Content-Type: image/png');
  2. $image=imagecreatetruecolor(100, 30);
  3. $color=imagecolorallocate($image, 255, 255, 255) ;
  4. imagefill($image, 20, 20, $color);
  5. //Contains only numbers
  6. // for($i=0;$i<4;$i++){
  7. // $font=6;
  8. / / $x=rand(5,10)+$i*100/4;
  9. // $y=rand(8, 15);
  10. // $string=rand(0, 9);
  11. // $color= imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
  12. // imagestring($image, $font, $x, $y, $string, $color);
  13. // }
  14. //Containing numbers and letters
  15. for($i=0;$i<4;$i++){
  16. $fontSize=6;
  17. $x=rand(5,10)+$i*100/4;
  18. $y=rand(5, 15);
  19. $data='abcdefghijklmnopqrstuvwxyz123456789';
  20. $string=substr($data,rand(0, strlen($data)),1);
  21. $color=imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
  22. imagestring($image, $fontSize, $x, $y, $string, $color);
  23. }
  24. //interference point element
  25. for($ i=0;$i<200;$i++){
  26. $pointColor=imagecolorallocate($image, rand(100, 255), rand(100, 255), rand(100, 255));
  27. imagesetpixel($image, rand(0, 100), rand(0, 30), $pointColor);
  28. }
  29. //Interference line elements
  30. for($i=0;$i<2;$i++){
  31. $linePoint=imagecolorallocate($ image, rand(150, 255), rand(150, 255), rand(150, 255));
  32. imageline($image, rand(10, 50), rand(10, 20), rand(80,90) , rand(15, 25), $linePoint);
  33. }
  34. imagepng($image);
  35. imagedestroy($image);
  36. ?>
Copy code

The above is the entire content of this article, I hope you all like it.

Verification code, php


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template