Posted By


assbach on 02/09/07

Tagged


Statistics


Viewed 629 times
Favorited by 7 user(s)

captcha calculation


/ Published in: PHP
Save to your folder(s)

This produces a JPG image with a calculation for spam-prevention. (with german written numbers)
An alternative to captcha images.


Copy this code and paste it in your HTML
  1. <?php
  2. $num = array(1,2,3,4,5,6,7,8,9);
  3. $words = array("[eins]","[zwei]","[drei]","[vier]","[fünf]","[sechs]","[sieben]","[acht]","[neun]");
  4. $plus = "+";
  5.  
  6. mt_srand((double)microtime()*1000000);
  7. $first = mt_rand(0,8);
  8. $second = mt_rand(0,8);
  9.  
  10. $ergebnis = $num[$first] + $num[$second];
  11. $showcode = $words[$first] . " + " . $words[$second] . " = ";
  12.  
  13. $_SESSION['mmmath'] = $ergebnis;
  14.  
  15. #echo $showcode;
  16. #echo $ergebnis;
  17.  
  18. $height = 20;
  19. #$width = 225;
  20. $width = strlen($showcode)*8+10;
  21. header('Content-type: image/jpeg');
  22. $image = @imagecreate($width,$height);
  23. imagecolorallocate($image, 238, 238, 238);
  24. $text_color = imagecolorallocate($image, 0, 0, 0);
  25. imagestring($image, 4, 2, 2, $showcode, $text_color);
  26.  
  27. #$bordercolor = imagecolorallocate($image, 80, 80, 80);
  28. #imagerectangle($image,0,0,$width-1,$height-1,$bordercolor);
  29.  
  30. imagejpeg($image);
  31.  
  32. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.