1. <?php
  2. /*
  3.   captcha.php
  4.   jQuery Fancy Captcha
  5.   www.webdesignbeach.com
  6.  
  7.   Created by Web Design Beach.
  8.   Copyright 2009 Web Design Beach. All rights reserved.
  9. */
  10. session_start(); /* starts session to save generated random number */
  11.  
  12. /* this compare captcha's number from POST and SESSION */
  13. if (isset($_POST['captcha'])) {
  14. if ($_POST['captcha'] == $_SESSION['captcha']) {
  15. echo "Passed!"; /* YOUR CODE GOES HERE */
  16. unset($_SESSION[captcha]); /* this line makes session free, we recommend you to keep it */
  17. } else {
  18. echo "Failed!";
  19. }
  20. } else {
  21. $rand = rand(0, 4);
  22. $_SESSION['captcha'] = $rand;
  23. echo $rand;
  24. }
  25.  
  26. ?>