I'm trying to use CAPTCHA images to validate comments. I've installed CAPTCHA and Comments, comments works fine alone. When the CAPTCHA option is turned on, no CAPTCHA image appears, but a CAPTCHA image is generated in modules\Captcha\images\captchas. The "Code in the picture" input appears on the page, but not the CAPTCHA image. Looks like the CAPTCHA image path is bad...HTML source shows the following:
Note the last slash is facing the wrong way. Also, this should be a relative URL, not the absolute path on the local disk. I noticed the changes in CMSM 1.04 made a change to the path in Windows, but upgrading did not fix it. The specified CAPTCHA is generated correctly, if I open the file manually and input the code, CAPTCHA validation works.
Here is all the relevant info:
CMSMS Version: 1.03 AND 1.04 (tried both)
Server OS: Windows XP Pro
Web Server: Apache 2.2.0 (using xampp distro)
Comments Version: 1.8.0
CAPTCHA Version: 0.1.1
PHP Version: 5.1.1
Not sure if this is an issue with CAPTCHA, Comments, or CMSMS, any ideas?
Incorrect image path for CAPTCHA
Re: Incorrect image path for CAPTCHA
This seems to have been a problem for a few others, here is my inelegant hack in PHP:
In modules\Captcha\lib\b2evo_captcha on line 395 replace this:
return str_replace($_SERVER['DOCUMENT_ROOT'],'',$this->tempfolder).$this->filename_prefix.$public.'.jpg';
with this
return 'http://AddressOfMyCMSMS.com/modules/Cap ... blic.'.jpg';
Replace AddressOfMyCMSMS.com with whatever is appropriate for your site. It's a hack but it works.
$_SERVER['DOCUMENT_ROOT'] returns the path to the local hard drive document root, not to the website root directory. Anyone with a better knowledge of PHP than me know how to fix this permanently?
In modules\Captcha\lib\b2evo_captcha on line 395 replace this:
return str_replace($_SERVER['DOCUMENT_ROOT'],'',$this->tempfolder).$this->filename_prefix.$public.'.jpg';
with this
return 'http://AddressOfMyCMSMS.com/modules/Cap ... blic.'.jpg';
Replace AddressOfMyCMSMS.com with whatever is appropriate for your site. It's a hack but it works.
$_SERVER['DOCUMENT_ROOT'] returns the path to the local hard drive document root, not to the website root directory. Anyone with a better knowledge of PHP than me know how to fix this permanently?
Re: Incorrect image path for CAPTCHA
That hack will work but you should also change the similar code on line 597 of the same file.
These 2 lines of code are designed to remove the beginning part of the variable $this->tempfolder (replace 'C:\xampplite\htdocs\' with '') then prepend what's left over (which should be the path to the web root) to the new image.
However if you do not have the correct path in $this->tempfolder the function str_replace will not do anything; it will fail to match the pattern it is looking for. You are then left with an incorrect path to your image, a path from the document root as you have.
so before hacking try checking that you have the correct paths in your config.php as this is where $this->tempfolder gets its value from, our host incorrectly reported that our web root began at '/homepages/....' when there is actually a directory preceding this it should be '/kunden/homepages/...', so we changed the relevant values in config.php and it worked.
The CMSMS online setup will also incorrectly report the webroot directory and set the values in config.php incorrectly.
These 2 lines of code are designed to remove the beginning part of the variable $this->tempfolder (replace 'C:\xampplite\htdocs\' with '') then prepend what's left over (which should be the path to the web root) to the new image.
However if you do not have the correct path in $this->tempfolder the function str_replace will not do anything; it will fail to match the pattern it is looking for. You are then left with an incorrect path to your image, a path from the document root as you have.
so before hacking try checking that you have the correct paths in your config.php as this is where $this->tempfolder gets its value from, our host incorrectly reported that our web root began at '/homepages/....' when there is actually a directory preceding this it should be '/kunden/homepages/...', so we changed the relevant values in config.php and it worked.
The CMSMS online setup will also incorrectly report the webroot directory and set the values in config.php incorrectly.
Last edited by baptiste on Mon Feb 05, 2007 5:15 pm, edited 1 time in total.
Re: Incorrect image path for CAPTCHA
Thanks, I'll check that out. Could the reason str_replace fails be due to the direction of slashes (I am running this on a windows server). I noticed a few other places in captcha where the slash direction was hard coded as a forward slash?
Re: Incorrect image path for CAPTCHA
hi,
I don't think that the slashes are anything to worry about, I think PHP treats them all internally as '/' and will convert them silently.
I don't think that the slashes are anything to worry about, I think PHP treats them all internally as '/' and will convert them silently.
Re: Incorrect image path for CAPTCHA
I had the exact same problem (on a winserver host), gonna try these fixes today!
Re: Incorrect image path for CAPTCHA
Version 0.2 should fix the captcha image not showing up in some cases (look here for more info).
This version should work without any hacks, let me know if it doesn't.
Regards,
D
This version should work without any hacks, let me know if it doesn't.
Regards,
D
Re: Incorrect image path for CAPTCHA
hi,
I've installed Captcha-0.2.1.xml on a CMS Made Simple version 1.0.4 site and it seems to work fine.
I think that the cache had to be cleared for it to work.
Excellent work!
I've installed Captcha-0.2.1.xml on a CMS Made Simple version 1.0.4 site and it seems to work fine.
I think that the cache had to be cleared for it to work.
Excellent work!