Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]CAPTCHA+rejestracja
moto0095
post
Post #1





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

Ostrzeżenie: (0%)
-----


Witam. Mam oto taki problem mam sobie kod CAPTHA :
  1. <?PHP
  2. function put_char($char,$rgb,$posx,$posy) {
  3. }
  4.  
  5. function confirm($string) {
  6. $config = array(
  7. 'font'=>'cactus_plain', // nazwa pliku z fontem ttf (bez rozszerzenia), nie moze zawierac spacji!
  8. 'fontpath'=>'.', // polozenie pliku z fontem
  9. 'image'=>'captcha.png', // nazwa obrazka typu PNG uzywanego jako background
  10. 'light'=>30, // jasnosc napisu, 100=bialy, 0=czarny
  11. 'saturation'=>90, // nasycenie koloru napisu, 0=szary, 100=najbardziej nasycony
  12. 'alpha'=>30, // przezroczystosc napisu, 0=bez przezroczystosci, 100=calkowicie transparentny
  13. 'imageheight'=>100,
  14. 'imagewidth'=>360
  15. );
  16.  
  17. putenv('GDFONTPATH=' . realpath($config['fontpath']));
  18. //$im = imagecreatefrompng($config['image']);
  19. $im = imagecreatetruecolor($config['imagewidth'], $config['imageheight']);
  20. if ($im) {
  21. $white = imagecolorallocate($im, 255, 255, 255);
  22. imagefilledrectangle($im, 1, 1, $config['imagewidth']-2, $config['imageheight']-2, $white);
  23. $maxfontheight=$config['imageheight']*0.7;
  24. $minfontheight=$config['imageheight']*0.4;
  25.  
  26. $px = ($config['imagewidth']-20)/(strlen($string));
  27.  
  28. header('Content-Type: image/png');
  29. header('Cache-control: no-cache, no-store');
  30.  
  31. $textcolor=mt_rand(0, 359);
  32. for ($i=0; $i<50; $i++) {
  33. $rgb=hls2rgb(mt_rand($textcolor+20, $textcolor+319),70,50);
  34. $color = imagecolorallocatealpha($im, $rgb[0], $rgb[1],$rgb[2],$config['alpha']);
  35. $angle=mt_rand(-15, 15);
  36. $fontheight=mt_rand($minfontheight/2, $minfontheight);
  37. $posx=mt_rand(0, $config['imagewidth']);
  38. $posy=mt_rand($fontheight, $config['imageheight']);
  39. imagettftext( $im, $fontheight, $angle, $posx, $posy, $color, $config['font'], chr(mt_rand(ord('A'),ord('Z'))) );
  40. }
  41.  
  42. $rgb=hls2rgb($textcolor,$config['light'],$config['saturation']);
  43. $color = imagecolorallocatealpha($im, $rgb[0], $rgb[1],$rgb[2],$config['alpha']);
  44. for ($i=0; $i<strlen($string); $i++) {
  45. $angle=mt_rand(-15, 15);
  46. $fontheight=mt_rand($minfontheight, $maxfontheight);
  47. $posx=$i*$px+mt_rand(0, $px/4)+10;
  48. $py = ($config['imageheight']+$fontheight)/2;
  49. imagettftext( $im, $fontheight, $angle, $posx, $py, $color, $config['font'], $string[$i] );
  50. }
  51.  
  52. $color = imagecolorallocate($im, 0, 0,0);
  53. // imagettftext( $im, 10, 0, 5, 15, $color, $config['font'], 'Fsck all SEO spammers!' );
  54. imagestring($im, 1,5, 5, 'Fsck all SEO spammers!', $color);
  55. imagepng($im);
  56. imagedestroy($im);
  57. }
  58. else
  59. die('Problem with file '.$config['image']);
  60. }
  61.  
  62. function XRGB($hh, $mm1, $mm2) {
  63. // funkcja pomocnicza
  64. $hh=$hh%360;
  65.  
  66. if ($hh < 60)
  67. return $mm1 + ($mm2 - $mm1) * $hh / 60;
  68. elseif ($hh < 180)
  69. return $mm2;
  70. elseif ($hh < 240)
  71. return $mm1 + ($mm2 - $mm1) * (240 - $hh) / 60;
  72. else
  73. return $mm1;
  74. }
  75.  
  76. function hls2rgb($h,$l,$s) {
  77. $il = ($l%100) / 100;
  78. $ih = ($h%360);
  79. $is = ($s%100) / 100;
  80. if ($il <= 0.5)
  81. $m2 = $il * (1 + $is);
  82. else
  83. $m2 = $il + $is - $il * $is;
  84.  
  85. $m1 = 2*$il - $m2;
  86.  
  87. if ($s == 0) {
  88. $ir = $il;
  89. $ig = $il;
  90. $ib = $il;
  91. }
  92. else {
  93. $ir = XRGB($ih + 120, $m1, $m2);
  94. $ig = XRGB($ih , $m1, $m2);
  95. $ib = XRGB($ih - 120, $m1, $m2);
  96. }
  97. return array(round($ir * 255),round($ig * 255),round($ib * 255));
  98. }
  99.  
  100. //confirm((strtoupper(!empty($_GET['txt'])?$_GET['txt']:'captcha')));
  101. ?>

(kod nie jest mój) i zanic nie mogę połączyć tego z formularzem rejestracji.
Wie ktoś jak to połączyć questionmark.gifquestionmark.gifquestionmark.gifquestionmark.gif smile.gif

Albo zna ktoś jakiś gotowiec, bo ja szukam i nic nie mogę znaleźdźquestionmark.gifquestionmark.gif
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 22:46