-4

I have this simple captcha script from online. I like it, and I edited it to suit my site, but was wondering if someone could edit it to add some random lines on the captcha itself as it is somewhat too simple.

I did find tutorials on how to do it but it was not working for me.

Here is the simple captcha script; I would love to modify it to have some random lines appear on the captcha:

   $width    = 150;
   $height   = 24;
   $length   = 5;
   $font     = 'caviardreams.ttf';
   $font_size   = 14;
   $bg_color = array(245, 245, 245);
   $chars    = 'ABCDEFGHKMNPQRSTUVWXYZ23456789';
   session_start();
   //putenv('GDFONTPATH=' . realpath('.'));
   $img = imagecreatetruecolor($width, $height);
   $bkgr = imagecolorallocate($img, $bg_color[0], $bg_color[1], $bg_color[2]);
   imagefilledrectangle($img, 0, 0, $width, $height, $bkgr);

   $code = '';
   for($i = 0; $i < $length; $i++)
   {
      $code .= $chr = $chars[mt_rand(0, strlen($chars)-1)];
      $r = rand(0, 192);
      $g = rand(0, 192);
      $b = rand(0, 192);
      $color = imagecolorallocate($img, $r, $g, $b);
      $rotation = rand(-35, 35);
      $x = 5+$i*(4/3*$font_size+2);
      $y = rand(4/3*$font_size, $height-(4/3*$font_size)/2);
      imagettftext($img, $font_size, $rotation, $x, $y, $color, $font, $chr);
   }

   $_SESSION['random_txt'] = md5($code);

   header("Content-type: image/png");
   header("Expires: Mon, 01 Jul 1998 05:00:00 GMT");
   header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
   header("Cache-Control: no-store, no-cache, must-revalidate");
   header("Cache-Control: post-check=0, pre-check=0", false);
   header("Pragma: no-cache");

   imagepng($img);
   imagedestroy($img);
Charlie
  • 11,380
  • 19
  • 83
  • 138
PHPLOVER
  • 7,047
  • 18
  • 37
  • 54
  • 2
    Why not just use a great captcha script already made and free to use? It is called `recpatcha` and is available from http://www.recaptcha.org – Jim Sep 07 '10 at 14:58
  • 1
    That would be: http://www.recaptcha.org/ – Evert Sep 07 '10 at 14:59
  • Hi i always did use recaptcha but i dislike it now, i don't like the fact that if javascript is disabled by user it displays awful on the webpage plus it's to clunky hence why i ditched recaptcha after using it for about 2 years, i redesigned my website and it just does not suit my site, plus i got 2 other methods that i have implemented with the captcha to help prevent spambots. I am just looking for someone to alter the code to add random lines for me if they don't mind, i don't want to use any other scripts i want to keep to this one as it's simple and not bogged down. Thanks – PHPLOVER Sep 07 '10 at 15:04
  • Then use SecurImage PHP Captcha. It works fine on GD and required NO javascript: http://www.phpcaptcha.org/ – shamittomar Sep 07 '10 at 15:08
  • Hi as i said i don't want to use anyother script thank you, i am not asking that, i don't want to sound rude but i asked if someone could kindly alter it for me not suggest captcha scripts, i know about them already, thank you. – PHPLOVER Sep 07 '10 at 15:12
  • SO is not for asking others to do your work for you. Could you explain the difficulties you are having and ask questions about that? –  Sep 08 '10 at 14:36

2 Answers2

3

Right before:

$_SESSION['random_txt'] = md5($code);

Insert:

for ($i=0;$i<100;$i++)
  imageline($img,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),imagecolorallocate($img,rand(0,63),rand(0,63),rand(0,63)));
bcosca
  • 17,371
  • 5
  • 40
  • 51
0

Given that you want to stick with that script, you can look at this scripts source and figure out how the do the design patterns. Sorry if this is not the answer you are looking for. The sections I would highlight for you to concentrate on would be:

/* generate random lines in background */
/* generate random dots in background */

Both of those items seem to be right up your alley of what you are wanting to do.

Jim
  • 18,673
  • 5
  • 49
  • 65