Home > Simple CAPTCHA >

Download cap_form.php

cap_form.php

Read cap_form.php

  1. <?php
  2. /*
  3.  * Notice the image src that is a php image generator.
  4.  * That's all ...
  5.  */
  6. ?>
  7. <div class="box">
  8. <h2>Post your comment</h2>
  9. <div class="commentform">
  10. <form method="post" action="cap_postdata.php">
  11. <input type="hidden" name="formId" value="comment:<?=$postId?>" />
  12. <span>Type the number below:</span><img width=120 height=30 src="cap_button.php" alt="random number" border="1" />
  13. <br />
  14. <input maxlength=5 size=5 name="audit" type="text" value="" />
  15. <input type="submit" value="Add comment" class="btn" />
  16. </form>
  17. </div>
  18. </div>
  19.  

Download cap_postdata.php

cap_postdata.php

Read cap_postdata.php

  1. <?
  2. require 'cap_audit.php';
  3.  
  4. if(audit()) {
  5.     /* echo put your code on successful captcha here */
  6. } else {
  7.     /* echo put your code on failed captcha here */
  8. }
  9. ?>
  10.  

Download cap_audit.php

cap_audit.php

Read cap_audit.php

  1. <?php
  2.  function audit() {
  3.   /* session_start(); */
  4.   $digit = $_SESSION['digit'];
  5.   $userdigit = $_POST['audit'];
  6.   session_destroy();  
  7.  
  8.   if (($digit == $userdigit) && ($digit > 1)) {
  9.     return true;
  10.   } else {
  11.     return false;
  12.   }
  13.  
  14. }
  15. ?>
  16.  

Download cap_button.php

cap_button.php

Read cap_button.php

  1. <?php
  2.  
  3. $image = imagecreate(120, 30);
  4.  
  5. $white    = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
  6. $gray    = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
  7. $darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50);
  8.  
  9. srand((double)microtime()*1000000);
  10.  
  11. for ($i = 0; $i < 30; $i++) {
  12.   $x1 = rand(0,120);
  13.   $y1 = rand(0,30);
  14.   $x2 = rand(0,120);
  15.   $y2 = rand(0,30);
  16.   imageline($image, $x1, $y1, $x2, $y2 , $gray);  
  17. }
  18.  
  19. for ($i = 0; $i < 5; $i++) {
  20. $cnum[$i] = rand(0,9);
  21. }
  22.  
  23. $x = 0;
  24. for ($i = 0; $i < 5; $i++) {
  25.  $fnt = rand(3,5);
  26.  $x = $x + rand(12 , 20);
  27.  $y = rand(7 , 12);
  28.  imagestring($image, $fnt, $x, $y, $cnum[$i] , $darkgray);
  29. }
  30.  
  31. $digit = "$cnum[0]$cnum[1]$cnum[2]$cnum[3]$cnum[4]";
  32.  
  33. $_SESSION['digit'] = $digit;
  34.  
  35. header('Content-type: image/png');
  36. imagepng($image);
  37. imagedestroy($image);
  38.  
  39. ?>
  40.  
  41.