form.php 887 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. // We need the session to check the phrase after submitting
  3. session_start();
  4. ?>
  5. <html>
  6. <?php
  7. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  8. // Checking that the posted phrase match the phrase stored in the session
  9. if (isset($_SESSION['phrase']) && $_SESSION['phrase'] === $_POST['phrase']) {
  10. echo "<h1>Captcha is valid !</h1>";
  11. } else {
  12. echo "<h1>Captcha is not valid!</h1>";
  13. }
  14. // The phrase can't be used twice
  15. unset($_SESSION['phrase']);
  16. }
  17. ?>
  18. <form method="post">
  19. Copy the CAPTCHA:
  20. <?php
  21. // See session.php, where the captcha is actually rendered and the session phrase
  22. // is set accordingly to the image displayed
  23. ?>
  24. <img src="session.php" />
  25. <input type="text" name="phrase" />
  26. <input type="submit" />
  27. </form>
  28. </html>