Spam protecting forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tompa
Forum Newbie
Posts: 10
Joined: Thu Mar 20, 2008 12:40 pm

Spam protecting forms

Post 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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Spam protecting forms

Post 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
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Spam protecting forms

Post 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/
Tompa
Forum Newbie
Posts: 10
Joined: Thu Mar 20, 2008 12:40 pm

Re: Spam protecting forms

Post 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?
mVeliki
Forum Newbie
Posts: 8
Joined: Mon Mar 17, 2008 4:42 pm

Re: Spam protecting forms

Post by mVeliki »

Yes, it is posible,
GD has few buil-in fonts,
just use function imagestring, at try variations of second parametar.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Spam protecting forms

Post 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
Tompa
Forum Newbie
Posts: 10
Joined: Thu Mar 20, 2008 12:40 pm

Re: Spam protecting forms

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Spam protecting forms

Post by John Cartwright »

imgejpeg wrote:bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )

Code: Select all

imagejpeg($NewImage, null, 100);//Output image to browser
Tompa
Forum Newbie
Posts: 10
Joined: Thu Mar 20, 2008 12:40 pm

Re: Spam protecting forms

Post by Tompa »

much better now ;) thanks jcart

... and again, how do you change fontsize and font family?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Spam protecting forms

Post by John Cartwright »

The 2nd parameter of imagestring(), I believe.
Tompa
Forum Newbie
Posts: 10
Joined: Thu Mar 20, 2008 12:40 pm

Re: Spam protecting forms

Post 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
Tompa
Forum Newbie
Posts: 10
Joined: Thu Mar 20, 2008 12:40 pm

Re: Spam protecting forms

Post 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?
Post Reply