S
S
Sergey Shevchenko2017-07-13 13:53:05
Zend Framework
Sergey Shevchenko, 2017-07-13 13:53:05

ZF1 Why does Captcha show the last character as an English letter when using Russian characters?

ZF1 Captcha when using Russian characters gives the last character as an English letter
Hello everyone. Who can tell in which direction to think?
I know where the error occurs, namely in the core of zend in `abstract class Zend_Captcha_Word` in this method

/**
     * Generate new random word
     *
     * @return string
     */
    protected function _generateWord()
    {
        $word       = '';
        $wordLen    = $this->getWordLen();
        $vowels     = $this->_useNumbers ? self::$VN : self::$V;
        $consonants = $this->_useNumbers ? self::$CN : self::$C;

        $totIndexCon = count($consonants) - 1;
        $totIndexVow = count($vowels) - 1;
        for ($i=0; $i < $wordLen; $i = $i + 2) {
            // generate word with mix of vowels and consonants
            $consonant = $consonants[Zend_Crypt_Math::randInteger(0, $totIndexCon, true)];
            $vowel     = $vowels[Zend_Crypt_Math::randInteger(0, $totIndexVow, true)];
            $word     .= $consonant . $vowel;
        }

        if (strlen($word) > $wordLen) {
            // *******************************************
            // * ВОТ ЗДЕСЬ НУЖНО, ЧТОБЫ БЫЛО mb_substr() *
            // *******************************************
            $word = substr($word, 0, $wordLen);
        }

        return $word;
    }

Here is an example of my code how I use it
Zend_Captcha_Word::$CN = ['а', 'в', 'г', 'д', 'е', 'ж', 'и', 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'э', 'ю', 'я', 1, 2, 3, 4, 5, 6, 7, 8, 9];
    Zend_Captcha_Word::$VN = range(0, 9);
    Zend_Captcha_Word::$V = ['с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'э', 'ю', 'я'];
    Zend_Captcha_Word::$C = ['а', 'в', 'г', 'д', 'е', 'ж'];
    $element = new Zend_Form_Element_Captcha('captcha', [
        'captcha' => [
            'captcha'        => 'Image',
            'wordLen'        => 7,
            'timeout'        => 120,
            'expiration'     => 300,
            'font'           => './fonts/myfont.ttf',
            'imgDir'         => './captcha/',
            'imgUrl'         => '/captcha/',
            'dotNoiseLevel'  => 40,
            'lineNoiseLevel' => 4,
            'class'          => 'img-thumbnail',
        ]
    ]);
    $element->setRequired(true)
        ->setLabel('Проверочный код')
        ->setAttrib('placeholder', 'Введите число')
       ->setAttrib('class', 'form-control')
        ->addDecorator(['row' => 'HtmlTag'], ['tag' => 'div', 'class' => 'form-group']);
    $this->addElement($element);

Sometimes it displays the symbol as it should, and sometimes it doesn't.
66a7546a09294cfea47247f6d58d857f.png91d1f7bd9c2547feb3ab4fe6f40fcd40.pnga3e9e721135644709f0426249579d315.pngc2e68ef22c4d459c91f818ca87deb0bd.png
Burned it in the debugger.
ce890f1e6a40447fb3548c1d73e0375b.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Farhod Daniyarov, 2018-02-23
@fudeglan

use the php function reload mechanism, man
namely in php.ini you need to add
mbstring.func_overload = 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question