Просмотр файла captcha.php

Размер файла: 1.92Kb
  1. <?php
  2. # Captcha v1.0 by Wapweb #
  3.  
  4. $width = 110;
  5. $height =30;
  6. $sign = rand(3,6);
  7. $code = '';
  8. ob_start();
  9. session_start();
  10. error_reporting(E_ALL & ~E_NOTICE);
  11. //$letters = array('a','b','c','d','f','g','h','i','j','k','m','n','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z','2','3','4','5','6','7','8','9');
  12. $letters = range('0','9');
  13. $figures = array('50','70','90','110','130','150','170','190','30');
  14. $img = imagecreatetruecolor($width,$height);
  15. $f1 = rand(220,255);
  16. $f2 = rand(220,255);
  17. $f3 = rand(220,255);
  18. $fon = imagecolorallocate($img , $f1,$f2,$f3);
  19. imagefill($img,0,0,$fon);
  20.  
  21. /*for ($j=0; $j<$width; $j++) {
  22. for ($i=0; $i<($height*$width)/100; $i++) {
  23. $color = imagecolorallocatealpha(
  24. $img,
  25. $figures[rand(0,count($figures)-1)],
  26. $figures[rand(0,count($figures)-1)],
  27. $figures[rand(0,count($figures)-1)],
  28. rand(10,30));
  29. imagesetpixel(
  30. $img,
  31. rand(0,$width),
  32. rand(0,$height),
  33. $color);
  34. }
  35. }*/
  36. for ($j=0; $j<$sign; $j++) {
  37. imageline($img, 0, rand(0,24), 130, rand(0,40), 0xDCDCDC);
  38. }
  39. for ($s=0; $s<80; $s++) {
  40. imagesetpixel(
  41. $img,
  42. rand(0,$width),
  43. rand(0,$height),
  44. $color);
  45. }
  46. for ($i=0; $i<$sign; $i++) {
  47. $h =1;
  48. $color = imagecolorallocatealpha(
  49. $img,
  50. $figures[rand(0,count($figures)-1)],
  51. $figures[rand(0,count($figures)-1)],
  52. $figures[rand(0,count($figures)-1)],
  53. rand(10,30));
  54. $letter = $letters[rand(0,sizeof($letters)-1)];
  55. if (empty($x)) $x = $width*0.08;
  56. else $x = $x + ($width*0.8)/$sign + rand(0,$width*0.02);
  57. if ($h == rand(1,2)) $y = (($height*1)/4) + rand (0,$height*0.1);
  58. else $y = (($height*1)/4) - rand(0,$height*0.1);
  59. $code.=$letter;
  60. if($h == rand(0,1)) $letter = strtoupper($letter);
  61. imagestring($img,6,$x,$y,$letter,$color);
  62. }
  63.  
  64. $_SESSION['code'] = $code;
  65. header("Content-type: image/jpeg");
  66. imagejpeg($img);
  67. ob_end_flush();
  68. ?>