Wicked::getCAPTCHA PHP Method

getCAPTCHA() public static method

Generate a CAPTCHA string.
public static getCAPTCHA ( boolean $new = false ) : string
$new boolean If true, a new CAPTCHA is created and returned. The current, to-be-confirmed string otherwise.
return string A CAPTCHA string.
    public static function getCAPTCHA($new = false)
    {
        global $session;
        if ($new || !$session->get('wicked', 'captcha')) {
            $captcha = '';
            for ($i = 0; $i < 5; ++$i) {
                $captcha .= chr(rand(65, 90));
            }
            $session->set('wicked', 'captcha', $captcha);
        }
        return $session->get('wicked', 'captcha');
    }

Usage Example

Esempio n. 1
0
 public function handleAction()
 {
     global $notification, $conf;
     $page = Wicked_Page::getPage($this->referrer());
     if (!$this->allows(Wicked::MODE_EDIT)) {
         $notification->push(sprintf(_("You don't have permission to edit \"%s\"."), $page->pageName()));
     } else {
         if (!empty($GLOBALS['conf']['wicked']['captcha']) && !$GLOBALS['registry']->getAuth() && Horde_String::lower(Horde_Util::getFormData('wicked_captcha')) != Horde_String::lower(Wicked::getCAPTCHA())) {
             $notification->push(_("Random string did not match."), 'horde.error');
             return;
         }
         $text = Horde_Util::getFormData('page_text');
         $changelog = Horde_Util::getFormData('changelog');
         if ($conf['wicked']['require_change_log'] && empty($changelog)) {
             $notification->push(_("You must provide a change log."), 'horde.error');
             $GLOBALS['page_output']->addInlineScript(array('if (document.editform && document.editform.changelog) document.editform.changelog.focus()'), true);
             return;
         }
         if (trim($text) == trim($page->getText())) {
             $notification->push(_("No changes made"), 'horde.warning');
         } else {
             $page->updateText($text, $changelog);
             $notification->push(_("Page Saved"), 'horde.success');
         }
         if ($page->allows(Wicked::MODE_UNLOCKING)) {
             $page->unlock();
         }
     }
     // Show the newly saved page.
     Wicked::url($this->referrer(), true)->redirect();
 }
All Usage Examples Of Wicked::getCAPTCHA