session.php 654 B

12345678910111213141516171819202122
  1. <?php
  2. // We need the session to store the correct phrase for later check
  3. session_start();
  4. // Including the autoload (you need to composer install in the main directory)
  5. require_once __DIR__.'/../vendor/autoload.php';
  6. use Gregwar\Captcha\CaptchaBuilder;
  7. // Creating the captcha instance and setting the phrase in the session to store
  8. // it for check when the form is submitted
  9. $captcha = new CaptchaBuilder;
  10. $_SESSION['phrase'] = $captcha->getPhrase();
  11. // Setting the header to image jpeg because we here render an image
  12. header('Content-Type: image/jpeg');
  13. // Running the actual rendering of the captcha image
  14. $captcha
  15. ->build()
  16. ->output()
  17. ;