Page 1 of 1

Spam protecting forms

Posted: Thu Mar 20, 2008 12:42 pm
by Tompa
Hey,

Is there anyway to use captcha images to protect forms without having FreeType Support on you webserver?

...or does anyone know how to just use a number instead of an image? have seen that kind too

Re: Spam protecting forms

Posted: Thu Mar 20, 2008 11:35 pm
by yacahuma
what do you mean by free type support. All you need if the gd library and you can copy a font from windows to your directory

Re: Spam protecting forms

Posted: Fri Mar 21, 2008 2:38 pm
by andym01480
If you can't do a captcha type thing yourself because no Freetype, outsource it. This one looked quite fun http://research.microsoft.com/asirra/

Re: Spam protecting forms

Posted: Sat Mar 22, 2008 9:28 am
by Tompa
haha dont think I'll use that ^^ lol

what I mean is this... I ran a GD Support test on my webserver and it said Freetype was not supported.
I have asked around and tried like 10 different captcha codes and all of them have required FreeType Support.

Is there any way to use/make a captcha without the need FreeType Support?
I have no clue what it really is, but I figured it has to do something with creating images...

Otherwise I can do with just a number instead of an image, do someone know where to find a securitycode script like this?

Re: Spam protecting forms

Posted: Sat Mar 22, 2008 10:11 am
by mVeliki
Yes, it is posible,
GD has few buil-in fonts,
just use function imagestring, at try variations of second parametar.

Re: Spam protecting forms

Posted: Sat Mar 22, 2008 12:02 pm
by andym01480
Didn't you like the little doggies? :lol:

Try this - from the above post, it should work!

Code: Select all

 
<?php
session_start();
$captchaTextSize = 7;
 
do {
 
    // Generate a random string and encrypt it with md5
 
    $md5Hash = md5( microtime( ) * mktime( ) );
 
    // Remove any hard to distinguish characters from our hash
 
    preg_replace( '([1aeilou0])', "", $md5Hash );
 
} while( strlen( $md5Hash ) < $captchaTextSize );
 
// we need only 7 characters for this captcha
 
$ResultStr = substr( $md5Hash, 0, $captchaTextSize );
 
 
$NewImage =imagecreatefrompng("../images/captcha.png");//image create by existing image and as back ground 
 
$LineColor = imagecolorallocate($NewImage,233,239,239);//line color 
$TextColor = imagecolorallocate($NewImage, 15, 103, 103);//text color-white
 
imageline($NewImage,1,1,40,40,$LineColor);//create line 1 on image 
imageline($NewImage,1,100,60,0,$LineColor);//create line 2 on image 
 
imagestring($NewImage, 5, 10, 5, $ResultStr, $TextColor);// Draw a random string horizontally 
 
$_SESSION['key'] = md5($ResultStr);// carry the data through session
 
header("Content-type: image/jpeg");// out out the image 
 
imagejpeg($NewImage);//Output image to browser 
 
?>
 
You can nick the background image from http://www.keepchickens.info/captcha.png

If not you could do a question and answer thing - have a database table with a bunch of questions humans can answer and md5 the answer as a hidden field or store it in the session

Re: Spam protecting forms

Posted: Mon Mar 24, 2008 11:59 am
by Tompa
Thanks for the code!

Is there a way to control the quality of the output jpg file? Its kinda bad ftm :P

...also, how do you change the font and fontsize?

Re: Spam protecting forms

Posted: Mon Mar 24, 2008 12:30 pm
by John Cartwright
imgejpeg wrote:bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )

Code: Select all

imagejpeg($NewImage, null, 100);//Output image to browser

Re: Spam protecting forms

Posted: Mon Mar 24, 2008 12:38 pm
by Tompa
much better now ;) thanks jcart

... and again, how do you change fontsize and font family?

Re: Spam protecting forms

Posted: Mon Mar 24, 2008 12:54 pm
by John Cartwright
The 2nd parameter of imagestring(), I believe.

Re: Spam protecting forms

Posted: Mon Mar 24, 2008 3:39 pm
by Tompa
hmm... maybe,
but what should I enter? Im not a php coder, except the really basic stuff... so I have no clue :P

Re: Spam protecting forms

Posted: Fri Apr 25, 2008 5:48 pm
by Tompa
if you have a look at andym01480 's code, could someone tell me how I can use it in my form?

- How do I get the captcha to show where I want it and what should I name the input field for the captcha code?
- How do I make it send the form when you have filled in the correct code and how do I make it display an error message if you enter the wrong code?