captcha problems

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

captcha problems

Post by paqman »

Hey,

I'm trying to create my own captcha and it's not going so well. My host says everything is installed to run it, so is there something wrong with my code?

Generator.php:

Code: Select all

header("Content-type: image/png");
session_start();

$md5 = md5(microtime() * mktime());
$string = substr($md5,0,5);

$captcha = imagecreatefrompng("captcha.png");
$line = imagecolorallocate($captcha,255,255,255);
$font = imagecolorallocate($captcha,204,204,204);

imageline($captcha,0,0,125,15,$line);
imageline($captcha,0,0,125,20,$line);
imageline($captcha,125,0,0,20,$line);
imagettftext($captcha,20,0,6,10,$font,"Arial.ttf",$string);

$_SESSION['key'] = md5($string);

imagepng($captcha);
imagedestroy($captcha);
Index.php:

Code: Select all

<img src="generator.php" border=0>
If I use imagestring then it works fine, but I'd like to make it more complicated using imagetfftext.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Could be a couple of problems. You might try 'arial.ttf' instead of "Arial.ttf" and check GDFONTPATH.
(#10850)
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

One of the problems will be that the browser won't update the pic on a reload du to the pic already in cache.

This can be avoided by adding a random number as query string to the generator.php
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I'm certain it's the font path. That happened to me when I first tried using Captchas too.
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Post by paqman »

So how would I check the GDFONTPATH? What should it be set to?
Post Reply