当前位置:Gxlcms > PHP教程 > PHP数字运算验证码

PHP数字运算验证码

时间:2021-07-01 10:21:17 帮助过:25人阅读

  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

人气教程排行