Forums / All Other Contributions/Addons / Captcha using TTF & GD

Captcha using TTF & GD

Views: 147,342

Results 21 to 40 of 593
16 Mar 2007, 7:56 AM
#21
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Captcha using TTF & GD

My local dev server is set-up with register_globals disabled (just like the production server I want to run the mod on). Could this be cause to my issue?

Megaman, do you have register globals on or off on your demo site?

Woody

16 Mar 2007, 7:59 AM
#22
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

v 2.3 16.03.2007 10:51

  1. Some Admin configuration adjustments added;
  2. Remove non CAPTCHA updated code from Review Write page;
  3. Add gif support;

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

16 Mar 2007, 8:02 AM
#23
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

Woodymon:

I see in web server error log:

[error] PHP Fatal error: imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png: fatal libpng error: zlib error in /home/my_account/public_html/my_shop/includes/classes/captcha.php on line 214

> ...
> So for testing I changed image type (Config > Captcha) from png to jpeg and try again... but image still does not display in browser. However this time different message in error log:
> 
> ```
client denied by server configuration: /home/my_account/public_html/my_shop/includes/templates/my_template/images/index.php

Does this last error indicate a possible htaccess mod-security issue?
This errors indicate that you use bad configurated server.
Woodymon:

The segment of relevant code from the class file:

if($this->img_type == 'png') {
imagepng($this->img, '', (int)$this->quality);
} elseif($this->img_type == 'gif') {
imagegif($this->img, '');
} else {
imagejpeg($this->img, '', (int)$this->quality);
}

> 
> How to change to gif? Config > CAPTCHA in the admin provides png and jpeg options but don't see how to set gif image type.
Gif support only by last 2.3 version.

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

16 Mar 2007, 8:14 AM
#24
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: Captcha using TTF & GD

a_berezin:

This errors indicate that you use bad configurated server.

Ha! I figured that much out. Just was inquiring if anyone had ideas how to resolve. My local server is set-up to emulate my production server on webhost. If it does not run on my local server then it will not run on web host. But to be certain I just installed a fresh Zen cart on same host machine production shop is running on and installed previous version of your mod (v2.2) and same exact errors observed. Hosting provider grepped through the server logs and did not find anything unusual but observed same errors in the server error log. He asked me if the mod requires register_globals enabled. I stated I did not know but probably not as the mod developer is super security conscious.

How would I test if CAPTCHA mod requires register_globals?

a_berezin:

Gif support only by last 2.3 version.

OK I will install and test the new version.

Anyone have ideas what might contribute to above reported errors? Thanks for any recommends.

Woody

16 Mar 2007, 8:26 AM
#25
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

Tips:
Script for testing CAPTCHA:

<?php
require('includes/application_top.php');

require(DIR_WS_CLASSES . 'captcha.php');
$captcha = new captcha();

if(isset($_POST['action']) && $_POST['action'] == 'GO') {
	if($captcha->validateCaptchaCode()) 
		echo 'You enter VALID code - "' . $_POST["captcha"] . '"';
	else
		echo 'You enter INVALID code - "' . $_POST["captcha"] . '"';
}
?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<?php
// BOF Captcha
if(is_object($captcha)) {
?>
<?php echo $captcha->img(); ?>
<?php echo $captcha->redraw_button(BUTTON_IMAGE_CAPTCHA_REDRAW, BUTTON_IMAGE_CAPTCHA_REDRAW_ALT); ?>
<br class="clearBoth" />
<label for="captcha"><?php echo TITLE_CAPTCHA; ?></label>
<?php echo $captcha->input_field('captcha', 'id="captcha"') . ' <span class="alert">' . TEXT_CAPTCHA . '</span>'; ?>
<br class="clearBoth" />
<?php
}
// EOF Captcha
?>
<input type="submit" name="action" value="GO" />
</form>

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

16 Mar 2007, 8:32 AM
#26
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

Woody!
I use this CAPTCHA more than six months on different hosting. And only you have so problems.
How can I help you if you can't give me any usefull information or url for you test site?

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

16 Mar 2007, 2:39 PM
#27
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: Captcha using TTF & GD

Andrew,

Thanks for the follow-up and the upgrades!I discovered there is one diff between the two servers. The production shop was recently moved to a server with different version of PHP. Not sure why I forgot something so significant.

Anyway, the good news is I now have your new v.2.3 CAPTCHA working on PHP 4.4.4. I see many nice new v2.3 options in admin!

But mod v2.2 is still not working on the server running PHP 5.1.6. Thus I will try your test script and also install new mod version 2.3.

Woody

16 Mar 2007, 3:27 PM
#28
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: Captcha using TTF & GD

Installed v.2.3 (on server running PHP 4.4.4)

Good News: I can change the width and height of the background image and change the code length. And the shadows appear behind the characters. And the random diagonal lines appear behind the characters.

Bad News: The redraw button does not respond. And the characters are small and vertical, and not rotated as expected. In admin (Config >CAPTCHA) I changed the max and min "chars" sizes to no effect.

I've tried all three image type options (png, jpeg, gif) to same effect.

All of the above applies to both the contact_us and login page.

Before I spend too much time investigating thought I'd check to see if others observe the same with v2.3.

Woody

16 Mar 2007, 4:58 PM
#29
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: Captcha using TTF & GD

Thanks again for the test script Andrew.

I installed both the test script and v2.3 on on Zen Cart 1.37 on a host running PHP 4.4.4 and all is good (well a few errors as reported above but the image displays in both Firefox and IE6).

But the test script does not display image on Zen Cart 1.37 running on PHP 5.1.6.

Not wanting to jump to conclusion but is there possibly a PHP version compatibility issue here?

Could others whom have success with the mod and/or success running the test script above, please post their PHP version? Thanks.

Woody

20 Mar 2007, 8:42 AM
#30
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

v 2.4 20.03.2007 11:39

  1. Support for GD 1;
  2. Use of a class dir instead of function opendir;

Woody!
Test this version.

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

20 Mar 2007, 4:04 PM
#31
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: Captcha using TTF & GD

Andrew-

Regards to upgrading from v1.33 to 1.34 it looks like the only file needing updating was the classes file, so that's what I did.

Same issues continue. CAPTCHA image does not display on the shop running on PHP5.

Error log entry shows:

File does not exist: /home/ergo/public_html/403.shtml
client denied by server configuration: /home/account/public_html/shop/includes/templates/my_template/images/index.php

And I tried out your new _test_captcha.php with same negative result.

I do see IMAGE_CAPTCHA _ALT displays where the CAPTCHA image should be. I'm assuming this a new define that needs to go into the language file?

Below is the generated source from the contact_us page:

<img id="captimg" src="http://www.domain.com/shop/captcha_img.php?0.588261001174405752" alt="IMAGE_CAPTCHA_ALT" title=" IMAGE_CAPTCHA_ALT " height="50" width="240">
<input src="includes/templates/my_template/buttons/english/button_redraw.gif" alt="Redraw Capture Image" title=" Redraw Capture Image " onclick="document.getElementById('captimg').src='http://www.domain.com/shop/captcha_img.php?'+Math.random();return false;" type="image">
<br class="clearBoth">
<label for="captcha">Verification code:</label>
<input name="captcha" id="captcha" type="text"> <span class="alert">* (case insensitive)</span>
<br class="clearBoth">

All of the above is for the shop running on PHP5.

I updated to v1.34 CAPTCHA on the server running PHP4 and the CAPTCHA image still displays. But font size remains tiny. Changing values for 'Chars minimum size' and 'Chars maximum size 'has no effect.

I am not understanding the meaning of "(1.0=Image Height)". Is that reference to pixel size or relative aspect ratio or some percentage of something?

Besides the default values I tried 24.0 and 36.0 respectively.

Is there anything I can tell my hosting provider what to look for regards he support required for this CAPTCHA mod.

I'm thinking possibly some server security configuration is disallowing the 0.588261001174405752 parameter appended to http://www.domain.com/shop/captcha_img.php?

<img src="http://www.domain.com/shop/captcha_img.php?0.588261001174405752">

Appreciate your advice and assistance in trying out different ideas.

Woody

20 Mar 2007, 4:29 PM
#32
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

Woodymon:

I do see IMAGE_CAPTCHA _ALT displays where the CAPTCHA image should be. I'm assuming this a new define that needs to go into the language file?
Sorry, forgotten. Fixed.

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

20 Mar 2007, 4:34 PM
#33
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

Woodymon:

I updated to v1.34 CAPTCHA on the server running PHP4 and the CAPTCHA image still displays. But font size remains tiny. Changing values for 'Chars minimum size' and 'Chars maximum size 'has no effect.
Similar that there are no fonts found.
Woodymon:

I am not understanding the meaning of "(1.0=Image Height)". Is that reference to pixel size or relative aspect ratio or some percentage of something?
Yes its a ratio. 1 corresponds to height of the image. 0.9 - 0.9 from height, 0.8 - 0.8 heights etc.

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

20 Mar 2007, 6:06 PM
#34
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: Captcha using TTF & GD

a_berezin:

Similar that there are no fonts found.

Thanks for that tip. And indeed after deleted the only TTF in the fonts directory the CAPTCHA image still displays with the six characters still at the same size. So knowing this will assist me in focusing my troubelshooting.

a_berezin:

Yes its a ratio. 1 corresponds to height of the image. 0.9 - 0.9 from height, 0.8 - 0.8 heights etc.
Ahhh... now I understand. 0.9 means the characters will display at 90% of the pixel height of the CAPTCHA image. Thanks for the clarification.

And FYI, I just submitted a follow-up message to my webhost regarding issue of the CAPTCHA image not displaying properly. I'm quite convinced now that some filtering rule(s) are in place causing the image to not display. I recall a similar error message a month ago or so when my shops product images generated by Image Handler 2 mysteriously quit displaying. After hemming and hawing over thias issue for two days the web host tech finally recalled they began "experimenting" with filtering on files ending with x80 (to protect against some infiltration technique tha's going around). Well if you have Image Handler 2 installed and you configure your small product images to display at 150wx80h size the filename will be appended with 150x80. Thus the webhost filtering rules put a stop to my product images for several days until they could figure out (remember) what they did to cause the issue. Doh! Document your changes boys and girls!! Needless to say they lost some credibility points on that one.

Woody

20 Mar 2007, 8:38 PM
#35
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: Captcha using TTF & GD

a_berezin:

Similar that there are no fonts found.

woodymon:

And indeed after deleted the only TTF in the fonts directory the CAPTCHA image still displays with the six characters still at the same size. .

Further testing shows the characters in the CAPTCHA image disappear after the verdana.TTF font is deleted AND when the three previously provided fonts (captcha_0.ttf...) are uploaded to the /fonts directory.

So that indicates the script is ndeed "seeing" the /fonts directory.

Wondering why the CAPTCHA characters don't display when the old fonts are installed but with no fonts installed, generic characters display.

Something is funky with this picture :wink2:

Woody

21 Mar 2007, 7:04 AM
#36
babygekko avatar

babygekko

New Zenner

Join Date:
Mar 2007
Posts:
19
Plugin Contributions:
0

Re: Captcha using TTF & GD

Just delete the "glob" thing from _getFileList it finally works on my server.

	function _getFileList($directory, $file_ext) {
		$file_list = array();
		if ($za_dir = @dir(rtrim($directory, '/')))
		{
				while ($filename = $za_dir->read()) {
					if (preg_match('/\.' . $file_ext . '$/i', $filename) > 0)
					{
						$file_list[] = $directory . $filename;
					}
				}
				sort($file_list);
		}
		return $file_list;
	}

Woodymon:

Further testing shows the characters in the CAPTCHA image disappear after the verdana.TTF font is deleted AND when the three previously provided fonts (captcha_0.ttf...) are uploaded to the /fonts directory.

So that indicates the script is ndeed "seeing" the /fonts directory.

Wondering why the CAPTCHA characters don't display when the old fonts are installed but with no fonts installed, generic characters display.

Something is funky with this picture :wink2:

Woody

21 Mar 2007, 9:35 AM
#37
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

babygekko:

Just delete the "glob" thing from _getFileList it finally works on my server.
What a problem with "glob" function? It's exist but don't work?

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

21 Mar 2007, 1:34 PM
#38
babygekko avatar

babygekko

New Zenner

Join Date:
Mar 2007
Posts:
19
Plugin Contributions:
0

Re: Captcha using TTF & GD

Yes, the glob function didn't work on my server (shared hosting, PHP4). I also had to delete the ob_start() and ob_end_clean() from captcha_img.php. Things work out perfectly right after that.

a_berezin:

What a problem with "glob" function? It's exist but don't work?

21 Mar 2007, 2:07 PM
#39
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Captcha using TTF & GD

Exist but didn't work.. Very strange. And what your hoster talk about this?

What a problem with ob_* functions in captcha_img.php? They prevent any output in application_top.php.

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

21 Mar 2007, 4:42 PM
#40
babygekko avatar

babygekko

New Zenner

Join Date:
Mar 2007
Posts:
19
Plugin Contributions:
0

Re: Captcha using TTF & GD

I just tried it on my other machine - WinXP with EasyPHP 1.8 (Apache 1.3.33 - PHP 4.3.10 - MySql 4.1.9) and same thing. On the XP/EasyPHP machine, I had to remove ob_start and ob_end_clean from showCaptchaImg before it could work. After that captcha shows fine on my XP.

I suppose it does exist because PHP > version 4.3

It's ok - I just had to remove those and it's looking good. My feedback: maybe you can find better color for the fonts? The colors just look ... you know .. :yuck: yucky... hehehe

a_berezin:

Exist but didn't work.. Very strange. And what your hoster talk about this?

What a problem with ob_* functions in captcha_img.php? They prevent any output in application_top.php.