Home  >  Article  >  Backend Development  >  PHP number operation verification code

PHP number operation verification code

WBOY
WBOYOriginal
2016-07-25 08:42:381059browse
  1. getValidate(100,30);
  2. function getValidate($w,$h){
  3. $img = imagecreate($w,$h);
  4. $gray = imagecolorallocate($img,255,255,255);
  5. $black = imagecolorallocate($img,rand(0,200),rand(0,200),rand(0,200));
  6. $red = imagecolorallocate($img, 255, 0, 0);
  7. $white = imagecolorallocate($img, 255, 255, 255);
  8. $green = imagecolorallocate($img, 0, 255, 0);
  9. $blue = imagecolorallocate($img, 0, 0, 255);
  10. imagefilledrectangle($img, 0, 0, 100, 30, $black);
  11. for($i = 0;$i < 80;$i++){
  12. imagesetpixel($img, rand(0,$w), rand(0,$h), $gray);
  13. }
  14. $num1 = rand(1,99);
  15. $num2 = rand(1,99);
  16. imagestring($img, 5, 5, rand(1,10), $num1, $red);
  17. imagestring($img,5,30,rand(1,10),getRand(), $white);
  18. imagestring($img,5,45,rand(1,10),$num2, $green);
  19. imagestring($img,5,65,rand(1,10),"=", $blue);
  20. imagestring($img,5,80,rand(1,10),"?", $red);
  21. header("content-type:image/png");
  22. imagepng($img);
  23. imagedestroy($img);
  24. }
  25. function getRand(){
  26. $code = rand(0,1);
  27. switch ($code) {
  28. case 0:
  29. return "+";
  30. break;
  31. case 1:
  32. return "-";
  33. break;
  34. default:
  35. # code...
  36. break;
  37. }
  38. }
  39. ?>
复制代码

验证码, 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