Page 1 of 1

captcha problems

Posted: Wed Jun 14, 2006 7:20 pm
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.

Posted: Wed Jun 14, 2006 7:28 pm
by Christopher
Could be a couple of problems. You might try 'arial.ttf' instead of "Arial.ttf" and check GDFONTPATH.

Posted: Thu Jun 15, 2006 3:58 am
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

Posted: Thu Jun 15, 2006 1:35 pm
by Ambush Commander
I'm certain it's the font path. That happened to me when I first tried using Captchas too.

Posted: Thu Jun 15, 2006 4:32 pm
by paqman
So how would I check the GDFONTPATH? What should it be set to?