PHP/GD/ Freetype : captcha for a comments form
- From: Jezza <jezza@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 16 Feb 2008 12:01:18 +0000
Hi
I am trying to create a captcha for a comments form, I do not get any
PHP errors but the image showing the captcha does not display. If I
right click "View Image" on the image placeholder I get "The requested
URL /test/81d8c.gif was not found on this server."
I am using PHP v.5.2.4 with GD & freetype enabled. I use an Apache 2 webserver.....any pointers gratefully received!
My code:
<HTML>
<HEAD><TITLE>Enter Your Feedback</TITLE>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
</HEAD>
<body>
<?php
$captcha=substr(md5(rand(0,65535)),rand(0,27),5);
$gifname=substr(md5(rand(0,65535)),rand(0,27),5);
$check=md5("SecretWord$captcha");
$font="font.ttf";
$size=imagettfbbox(24,0,$font,$captcha);
$width=$size[2]+$size[0]+6;
$height=abs($size[1])+abs($size[7])+5;
$im=imagecreatetruecolor($width,$height);
$bg=imagecolorallocate($im,0,0,0);
$fg=imagecolorallocate($im,255,255,255);
imagefilledrectangle($im,0,0,$width,$height,$bg);
imagettftext($im,24,0,2,abs($size[5])+2,$fg,$font,$captcha);
imagegif($im,"gifname.gif");
imagedestroy($im);
echo<<<_END
<p><font size="6"><strong><a name="intro"></a></strong></font></p>
<p align="center"><img src="logo.gif" > </p>
<H3> If you are a past customer, Please leave feedback</h3>
<img src=$gifname.gif align=left>
Please enter this text <br> in the box below<br>
<form method="post" action="store.php">
<input type=hidden name=check value=$check>
<input type=hidden name=gifname value=$gifname>
<input type=text name=captcha size=20>
<Table border="0" cellspacing="0">
<tr><td>Name</TD><td><input name="name" type="text" id="name"></td></tr>
<tr><td valign="top">Comments: </td><td><textarea name="comment" cols=50
wrap="VIRTUAL"></textarea></td></tr>
<tr><td> </td><td><input type="submit" name="Submit"
value="submit"</td></tr>
</table>
</form>
_END;
?>
</BODY>
</HTML>
.
- Follow-Ups:
- Re: PHP/GD/ Freetype : captcha for a comments form
- From: Jerry Stuckle
- Re: PHP/GD/ Freetype : captcha for a comments form
- From: Norman Peelman
- Re: PHP/GD/ Freetype : captcha for a comments form
- From: J.O. Aho
- Re: PHP/GD/ Freetype : captcha for a comments form
- Prev by Date: Re: Using C libraries and PHP - calling functions in external libraries
- Next by Date: Re: PHP/GD/ Freetype : captcha for a comments form
- Previous by thread: Using C libraries and PHP - calling functions in external libraries
- Next by thread: Re: PHP/GD/ Freetype : captcha for a comments form
- Index(es):
Relevant Pages
|