user2883741
user2883741

Reputation: 1

Captcha generator

I made a "Captcha generator" with PHP. so if I open the Page it always shows me the icon when a image isn't found.

 <?php
   session_start();
   unset($_SESSION['captcha_spam']);

   function randomString($len) {
      function make_seed(){
         list($usec , $sec) = explode (' ', microtime());
         return (float) $sec + ((float) $usec * 100000);
      }
      srand(make_seed());  

      //Der String $possible enthält alle Zeichen, die verwendet werden sollen
      $possible="ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789";
      $str="";
      while(strlen($str)<$len) {
        $str.=substr($possible,(rand()%(strlen($possible))),1);
      }
   return($str);
   }

   $text = randomString(5);  //Die Zahl bestimmt die Anzahl stellen
   $_SESSION['captcha_spam'] = $text;

   header('Content-type: image/png');
   $img = ImageCreateFromPNG('captcha.PNG'); //Backgroundimage
   $color = ImageColorAllocate($img, 0, 0, 0); //Farbe
   $ttf = $_SERVER['DOCUMENT_ROOT']."XFILES.TTF"; //Schriftart
   $ttfsize = 25; //Schriftgrösse
   $angle = rand(0,5);
   $t_x = rand(5,30);
   $t_y = 35;
   imagettftext($img, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $text);
   imagepng($img);
   imagedestroy($img);
?>

anyone an ideea why it doesnt works >.<

Thanks fpr help

Upvotes: 0

Views: 415

Answers (1)

Sammitch
Sammitch

Reputation: 32272

  1. You can't declare a function inside of another function, at least not how you're doing it here.
  2. Using srand() has been pointless since PHP 4.2.

So just remove that entire make_seed() function and the call to srand() and your code will probably work.

Upvotes: 1

Related Questions