Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2. ###############################################################
  3. # Anti-spam Image Generator (CAPTCHA) 1.0
  4. ###############################################################
  5. # For updates visit http://www.zubrag.com/scripts/
  6. ###############################################################
  7.  
  8. // Font name to use. Make sure it is available on the server.
  9. // You could upload it to the same folder with script if it cannot find font.
  10. // By default it uses arial.ttf font.
  11. $font = 'arial';
  12.  
  13. // list possible characters to include on the CAPTCHA
  14. $charset = '0123456789';
  15.  
  16. // how many characters include in the CAPTCHA
  17. $code_length = 6;
  18.  
  19. // antispam image height
  20. $height = 20;
  21.  
  22. // antispam image width
  23. $width = 80;
  24.  
  25. ############################################################
  26. #  END OF SETTINGS
  27. ############################################################
  28.  
  29. // this will start session if not started yet
  30. @session_start();
  31.  
  32. $code = '';
  33. for($i=0; $i < $code_length; $i++) {
  34.   $code = $code . substr($charset, mt_rand(0, strlen($charset) - 1), 1);
  35. }
  36.  
  37. $font_size = $height * 0.7;
  38. $image = @imagecreate($width, $height);
  39. $background_color = @imagecolorallocate($image, 255, 255, 255);
  40. $noise_color = @imagecolorallocate($image, 20, 40, 100);
  41.  
  42. /* add image noise */
  43. for($i=0; $i < ($width * $height) / 4; $i++) {
  44.   @imageellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
  45. }
  46. /* render text */
  47. $text_color = @imagecolorallocate($image, 20, 40, 100);
  48. @imagettftext($image, $font_size, 0, 7,17,
  49.               $text_color, $font , $code)
  50.   or die('Cannot render TTF text.');
  51.  
  52. /* output image to the browser */
  53. header('Content-Type: image/png');
  54. @imagepng($image) or die('imagepng error!');
  55. @imagedestroy($image);
  56. $_SESSION['AntiSpamImage'] = $code;
  57. exit();
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement