Latest news from Xavier Media
It is currently Fri Jul 03, 2009 11:47 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Need a good captcha generating php script
PostPosted: Tue Apr 10, 2007 9:30 am 
Offline

Joined: Wed Feb 04, 2009 2:00 am
Posts: 0
Hello,

I need a good captcha generating php script. I searched on Google but din't found anything useful so far, I am interested in your personal suggestions, some php script that is easy to install and generates strong captchas.
:idea:


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 2:41 pm 
Offline
XavierForum.com Admin
XavierForum.com Admin
User avatar

Joined: Tue Mar 15, 2005 4:37 pm
Posts: 807
Location: Sweden
I don't know of any good script, so I simply wrote some code on my own.

Create a file called functions.php on your server and copy this code to it:
Code:
<?
function captcha_check($action)
{
   ///////////////////// Change these settings /////////////////////
   // The fonts to use. Change to any fonts you like, you can even
   // add as many as you like.
   $fonts = array("baveuse3.ttf","international.ttf","no_problem.ttf");

   // Background images to write text on. Make sure they are JPG files!
   // The pictures should be 160x50 in size.
   $pictures = array("1.jpg","2.jpg");

   // Set this to a secret word only you know about. Letters and numbers
   // are both OK!
   $secretword = "set this to a secret word only you know about";

   ////////////////// No more changes are needed ///////////////////
   $txt = substr(md5($_SERVER[REMOTE_ADDR] ." ". date('d') ." ". date('m') ." ". date('h') ." ". $secretword),3,5);

   if ($action == "img")
   {
      Header("Content-type: image/jpg");

      $numpic = rand(0,(count($pictures)-1));
      $im = imagecreatefromjpeg($pictures[$numpic]);

      $white = ImageColorAllocate($im, 255, 255, 255);
      $black = ImageColorAllocate($im, 0, 0, 0);
      $i = 0;
      while ($i < 5)
      {
         $angle = 15 - rand(0,40);
         $fnum = rand(0,(count($fonts)-1));
         $font = $fonts[$fnum];
         $fontsize = 25;
      
         ImageTTFText($im,$fontsize,$angle,($i * 30 + 5),36,$black,$font,substr($txt,$i,1));
         $i++;
      }

      Imagejpeg($im);
      ImageDestroy($im);
   }
   else
   {
      if ($txt == $action)
      {
         return 1;
      }
      else
      {
         return 0;
      }
   }
};
?>
Include functions.php in any file where you want to do the check, then create a new file called image.php:
Code:
<?
include("functions.php");
captcha_check("img");
?>
Image will simply show the image to the end users so whereever you want to show the image you simply add:
Code:
<IMG SRC="image.php" BORDER=0 ALT="Fill in the numbers and letters you see in this picture in the field below" /><BR />
Here's a sample script that will ask the user for some letters and numbers. If the users enters the correct letters a short message show up:
Code:
<?
include("functions.php");
if ($_POST['do'] == "check")
{
   // Do the check if the user entered the same numbers/letters as the picture.
   if (captcha_check($_POST['letters']))
   {
      // The user wrote correct combination of letters and numbers
      echo '<P><STRONG><FONT COLOR=green>You entered the correct text!</FONT></STRONG></P>';
   }
   else
   {
      //Sorry, please try again.
      echo '<P><FONT COLOR=red>Sorry, wrong text! Try again.</FONT></P>';
   }
}
?>
<FORM METHOD=post ACTION="<? echo $_SERVER[PHP_SELF]; ?>">
<INPUT TYPE=hidden NAME=do VALUE=check>
<IMG SRC="image.php" BORDER=0 ALT="Fill in the numbers and letters you see in this picture in the field below" /><BR />
<B>Fill in the numbers and letters you see on the picture above:</B><BR>
<INPUT TYPE=text NAME=letters SIZE=5><INPUT TYPE=submit VALUE="Submit!">
</FORM>
You can see this example live at http://www.sampleaddress.com/captcha/index.php

/Andreas

_________________
Xavier Media
Advertise for free at XavierMedia.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 11:56 am 
Offline

Joined: Wed Feb 04, 2009 2:00 am
Posts: 0
Thank you for your suggestions! So far I also found Captcha Creator http://www.captchacreator.com which seems easy to install and works nice!

Thanks again for advice


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 5:13 pm 
Offline

Joined: Sun Mar 08, 2009 11:16 pm
Posts: 0
Thanks for this code bylla! It will be useful in creating my website, forms, etc. :)

danielus wrote:
Thank you for your suggestions! So far I also found Captcha Creator http://www.captchacreator.com which seems easy to install and works nice!

Thanks again for advice

Yeah, it does seem easy to use, but why pay up to $65 USD for that, when you can use this for free? I could understand if it was cheaper, but just for a Captcha? :P


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron

Actress | Mortgages | Credit Score | Mortgages | Mortgage Calculator

Portal » Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[
SEO MOD © 2007 StarTrekGuide ]