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

Размер файла: 1.24Kb
  1. <?php
  2. session_start();
  3.  
  4. $code = mt_rand(1111, 9999);
  5. $_SESSION['captcha'] = $code;
  6.  
  7. $code1 = substr($code, 0, 1);
  8. $code2 = substr($code, 1, 1);
  9. $code3 = substr($code, 2, 1);
  10. $code4 = substr($code, 3, 1);
  11.  
  12. $img = imagecreate(42, 18);
  13. $fon = imagecolorallocate($img, 255, 255, 255);
  14. imagefill($img, 0, 0, $fon);
  15.  
  16. $color1 = imagecolorallocate($img, mt_rand(0,204), mt_rand(0,204), mt_rand(0,204));
  17. $color2 = imagecolorallocate($img, mt_rand(0,204), mt_rand(0,204), mt_rand(0,204));
  18. $color3 = imagecolorallocate($img, mt_rand(0,204), mt_rand(0,204), mt_rand(0,204));
  19. $color4 = imagecolorallocate($img, mt_rand(0,204), mt_rand(0,204), mt_rand(0,204));
  20.  
  21. imagestring($img, 5, mt_rand(2,3), mt_rand(0,3), $code1, $color1);
  22. imagestring($img, 5, mt_rand(11,12), mt_rand(0,3), $code2, $color2);
  23. imagestring($img, 5, mt_rand(20,21), mt_rand(0,3), $code3, $color2);
  24. imagestring($img, 5, mt_rand(29,30), mt_rand(0,3), $code4, $color3);
  25.  
  26. for($i = 0; $i < 5; $i++)
  27. {
  28. $temp_color = imagecolorallocate($img, 204, 204, 204);
  29. $pos = array(mt_rand(0,42), mt_rand(0,18), mt_rand(0,42), mt_rand(0,18));
  30.  
  31. imageline($img, $pos[0], $pos[1], $pos[2], $pos[3], $temp_color);
  32. }
  33.  
  34. header('Content-type: image/png');
  35. imagepng($img);
  36. imagedestroy($img);
  37. exit();
  38. ?>