问题
OC 1.5.1.3, the Captcha image doesn't show on none of these pages:
- product / review section
- contact page
- by accessing this http://www.directmall.co.uk/index.php?route=information/contact/captcha (the direct link which should generate the image)
I can't see any errors (Apache logs / error.txt file). I can't see any spaces within the language files - in fact I've redownloaded the entire EN package just to make sure..
I suspect a broken dependency (even if I have GD.. there must be something else..); disabled entirely caching - need assistance!
Back in 2009 I've found trails of such errors on forums but it seems there was a language-file problem, meaning trails of spaces were sending the page headers earlier than normal - but I've checked most of the files I thought to be involved and I've cleaned all the extra spaces - with no result.
Thanks, Bogdan
回答1:
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;
}
回答2:
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 !
回答3:
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 ?>
,
回答4:
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();
回答5:
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.
回答6:
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.
回答7:
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/
来源:https://stackoverflow.com/questions/8263452/opencart-oc-1-5-1-3-captcha-error