PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/quicky/classes/plugins/addons/QCAPTCHA.class.session.php

https://bitbucket.org/seyar/parshin.local
PHP | 28 lines | 28 code | 0 blank | 0 comment | 6 complexity | 8bf81c51252f9b60e118e5815c9d3346 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. class QCAPTCHA extends QCAPTCHA_Abstract {
  3. public function __construct($properties = array()) {
  4. require_once QUICKY_DIR.'plugins/Captcha/Captcha_draw.class.php';
  5. $CAPTCHA = new CAPTCHA_draw;
  6. $CAPTCHA->generate_text();
  7. if (!session_id()) {
  8. session_start();
  9. }
  10. if (!isset($_SESSION['captcha'])) {
  11. $_SESSION['captcha'] = array();
  12. }
  13. $this->_imgid = -1;
  14. while ($this->_imgid == -1 or isset($_SESSION['captcha'][$this->_imgid])) {
  15. $this->_imgid = rand(0,mt_getrandmax());
  16. }
  17. $_SESSION['captcha'][$this->_imgid] = array($CAPTCHA->text,0);
  18. foreach ($properties as $k => $v) {
  19. $this->$k = $v;
  20. }
  21. }
  22. public function validate() {
  23. $id = isset($_REQUEST['captcha_id'])?strval($_REQUEST['captcha_id']):'';
  24. $r = isset($_SESSION['captcha'][$id]) && (strtolower($this->getValue()) == strtolower($_SESSION['captcha'][$id][0]));
  25. unset($_SESSION['captcha'][$id]);
  26. return $r;
  27. }
  28. }