Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Błąd z zabezpieczeniem captcha
Forum PHP.pl > Forum > Przedszkole
PGmajster
Witam, mam problem z zabezpieczeniem captcha. Nie wyświetla mi obrazka, a wgrałem go na ftp i podałem poprawną ścieżkę. Możliwe, że narobiłem kilka błędów, tak więc podam Wam dwa pliki i chciałbym prosić o pomoc w naprawie.

image.php - generuje obrazek captcha
  1. <?
  2.  
  3.  
  4. mysql_connect("localhost", "USER", "HASLO") or die ("Can not connect to the datebase");
  5. mysql_select_db("captcha") or die ("Can not choose datebase " . mysql_error());
  6.  
  7. $result_captcha = mysql_query("SELECT * FROM captcha WHERE hash = '$_GET[hash]' AND code = '$_GET[code]'") or die (mysql_error());
  8. $get_captcha = mysql_fetch_array($result_captcha) or die (mysql_error());
  9.  
  10. $imgn = 'red.png';
  11. $image = imagecreatefrompng($imgn);
  12.  
  13. $red = imagecolorallocate($image, 70, 0, 0);
  14. $black = imagecolorallocate($image, 0, 0, 0);
  15.  
  16. imagettftext($image, 45, 15, 15, 110, $red, 'harrington.ttf', $get_captcha['code']);
  17. imagettftext($image, 10, 0, 140, 115, $black, 'arial.ttf', 'xxxl');
  18.  
  19. header('content-type: image/png');
  20.  
  21. imagepng($image);
  22. imagedestroy($image);
  23.  
  24. ?>



formularz.php - główny plik wyświetlający formularz + captcha
  1. <?
  2. mysql_connect("localhost", "root", "test123") or die ("Can not connect to the datebase");
  3. mysql_select_db("captcha") or die ("Can not choose datebase " . mysql_error());
  4. $result_captcha = mysql_query("SELECT hash, code FROM captcha ORDER BY RAND() LIMIT 1") or die (mysql_error());
  5.  
  6. $get_captcha = mysql_fetch_array($result_captcha) or die (mysql_error());
  7.  
  8. ?>
  9. <form action="add.php" method="post">
  10. <img width="256" height="120" src="http://southcraft.pl/image.php?hash=<?=$get_captcha['hash'] ?>">
  11. <input type = "text" name="code">
  12.  
  13. <input type="hidden" name="hash" value="<?=$get_captcha['hash'] ?>"><br />
  14. <input type="submit" class="input_submit" name="submit" value="Wyślij"/>
  15. </form>



Proszę o wytypowanie błędów i o poprawę kodu. Z góry dziękuje za pomoc.
Spawnm
Kod podatny na sql injection + najgorsze rozwiązanie captchy jakie w życiu widziałem...
Wynik obrazka captchy trzymaj w sesji, unikniesz operacji na db wink.gif
PGmajster
Mógłbyś mi zapodać jakiś dobry poradnik na captche, aby działało na systemie: podaje kod i gdy dobry to przekierowuje na adres.php

Szukałem, ale nie mogłem znaleźć tylko to znalazłem.

Do zamknięcia. Użyłem reCaptcha Google smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.