form.php 999 B

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