Opencart, OC 1.5.1.3, captcha error

天涯浪子 提交于 2019-12-05 16:09:35

FYI I had this same problem and this solution (change to system\library\captcha.php) did make the captcha image display successfully and the form passes validation:

function getCode(){
$out = ob_get_contents();
$out = str_replace(array("\n", "\r", "\t", " "), "", $this->code);
ob_end_clean();

    return $out;
}

For OC 1.5.* Go to

system\library\captcha.php

Find function getCode() Replace this function to

function getCode(){
$code= ob_get_contents();
$code= str_replace(array("\n", "\r", "\t", " "), "", $this->code);
ob_end_clean()    return $code; }

Now For OC 2.1.* Go to

Catalog/controller/captcha/basic-captcha

Find $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6);

place below code after this

    $code= ob_get_contents();
    $code= str_replace(array("\n", "\r", "\t", " "), "",$this->session->data['captcha']);
    ob_end_clean();
    $this->session->data['captcha'] = $code;

And For OC 2.3.* Go to

Catalog/controller/Extension/captcha/basic-captcha.php Find $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6); Place below code after this

    $code= ob_get_contents();
    $code= str_replace(array("\n", "\r", "\t", " "), "",$this->session->data['captcha']);
    ob_end_clean();
    $this->session->data['captcha'] = $code;

Its helpfull !

Doing a view-source:http://www.directmall.co.uk/index.php?route=information/contact/captcha on Google Chrome showed me that there's a whitespace at the front of the content of the image.

You might have accidentally outputted "\n" somewhere in your code before <?php or after ?>,

alper çevik

you should add this code after your getcode function (captcha.php in the library)

$out = ob_get_contents();
$out = str_replace(array("\n", "\r", "\t", " "), "", $input);
ob_end_clean();

Just to clarify for anyone looking for this. system/library/captcha.php

change function line 11 getCode()

to this:

function getCode(){
    //return $this->code;
    $out = ob_get_contents();
            $out = str_replace(array("\n", "\r", "\t", " "), "", $input);
            ob_end_clean();

            return $out;
}

This ought to do it.

daniel

I had the same problem and i my particular case, this was the solution. Probably when fixing product.php some blank lines were introduced, which are extremely difficult to debug. In any case this code :

$out = ob_get_contents();
$out = str_replace(array("\n", "\r", "\t", " "), "", $input);
ob_end_clean();

return $out;

did fix it, since it cleans anything that should not be there.

hope it helps anyone.

I came across this issue recently and this common solution (that worked for me before) didn't work:

$out = ob_get_contents();
$out = str_replace(array("\n", "\r", "\t", " "), "", $input);
ob_end_clean();
return $out;

I noticed that the showImage() method in /system/library/captcha.php accesses $this->code directly rather than using its getter, getCode(). That means it's bypassing the function to strip whitespace.

However, modifying the constructor like this did the trick:

function __construct() { 
    $this->code = substr(sha1(mt_rand()), 17, 6); 
    $this->code = str_replace(array("\n", "\r", "\t", " "), "", $this->code);
}

More info and a vQmod extension to apply this fix can be found here: http://www.antropy.co.uk/blog/opencart-captcha-not-working-jfif/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!