Примитивная капча
- sub capcha {
- $url =$_[0];
- @array=('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9');
- $a=0;
- $code = "";
- $raz = @array;
- while($a<8) {
- $code .=@array[rand($raz)];
- $a++;
- }
- $im = new GD::Image(100, 20);
- $white = $im->colorAllocate(255,255,255);
- $black = $im->colorAllocate(0,0,0);
- $red = $im->colorAllocate(255,0,0);
- $im->transparent($white);
- $im->interlaced('true');
- $im->rectangle(0, 0, 99, 19, $black);
- $im->string(gdGiantFont,1,1,$code,$red);
- open(PICTURE, ">tmp/$url.png");
- binmode PICTURE;
- print PICTURE $im->png;
- close PICTURE;
- open(LOG,">>tmp/$url.txt");
- print(LOG "$code\n");
- close(LOG);
- return $url;
- }
- #удаляем просроченые файлы
- #код писала уже
- del_bad("tmp",5); #5 минут хватит
- $rand = pass(18);
- $cap=capcha($rand);
- print"<img src =\"tmp/$cap.png\">\n";
- print "<input type=\"text\" name=\"capcha\">\n";
- print "<input type=\"hidden\" name=\"cap\" value=\"$cap\">\n";