PHP数字运算验证码

php教程评论423 views阅读模式
  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;

复制代码

企鹅博客
  • 本文由 发表于 2020年8月21日 22:49:59
  • 转载请务必保留本文链接:https://www.qieseo.com/315211.html

发表评论