Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][MySQL]Czy to aby bezpieczne? SQL Injection.
Forum PHP.pl > Forum > Przedszkole
Siper
Chciałbym się zapytać czy podany poniżej skrypt jest dobrze zabezpieczony przed atakiem SQL Injection?

  1. <?php
  2. $dbh = mysql_connect("xxxx", "xxxx", "xxx");
  3. $db = mysql_select_db("xxxx");
  4. $id = mysql_real_escape_string($_GET['id']);//Pobieranie zmiennej id + zabezpieczenie przed SQL Injection
  5.  
  6. if (!isset($_GET['id'])) { //Sprawdzanie czy wpisano cos do id
  7. exit("Wpisz id!");
  8. }
  9.  
  10. $sql = mysql_query("SELECT * FROM `mybb_users` WHERE username='$id'") or die(mysql_error()); //Pobieranie informacji z bazy sql
  11. $num = mysql_fetch_array($sql); //Wyniki
  12.  
  13. if (empty($num['username'])) { exit("Nie ma takiego użytkownika!"); } //Sprawdzanie czy podany użytkownik w ogóle istnieje
  14.  
  15. $Font_File = 'sans.ttf';
  16. $Background_Picture = 'syg1.png';
  17. $final_image = imageCreateFromPng($Background_Picture);
  18. $white = imagecolorallocate($final_image, 255, 255, 255);
  19.  
  20. // Kolor reputacji w zależności od ilości
  21. if($num['reputation'] == 0){
  22. $rep_color = $white; // Kolor Biały
  23. }elseif($num['reputation'] > 0){
  24. $rep_color = imagecolorallocate($final_image, 0, 255, 0); // Kolor Zielony
  25. }elseif($num['reputation'] < 0){
  26. $rep_color = imagecolorallocate($final_image, 255, 0, 0); // Kolor Czerwony
  27. }
  28.  
  29. // Kolor nicku w zależności od grupy (Admin = Czerwony, Mod = Zielony, Reszta = Biały)
  30. if($num['usergroup'] == 4){
  31. $user_color = imagecolorallocate($final_image, 255, 0, 0); // Kolor Czerwony - Admin
  32. }elseif($num['usergroup'] == 3){
  33. $user_color = imagecolorallocate($final_image, 0, 255, 0); // Kolor Zielony - Mod
  34. }else{
  35. $user_color = $white; // Kolor Biały - Reszta
  36. }
  37.  
  38. // Tekst
  39. imagettftext($final_image, 8, 0, 160, 55, $user_color, $Font_File, $num['username']);
  40. imagettftext($final_image, 8, 0, 160, 65, $white, $Font_File, $num['postnum']);
  41. imagettftext($final_image, 8, 0, 160, 75, $rep_color, $Font_File, $num['reputation']);
  42.  
  43. // Wynik
  44. imagettftext($final_image, 8, 0, 85, 55, $white, $Font_File, 'Nick:');
  45. imagettftext($final_image, 8, 0, 85, 65, $white, $Font_File, 'Posty:');
  46. imagettftext($final_image, 8, 0, 85, 75, $white, $Font_File, 'Reputacja:');
  47.  
  48.  
  49.  
  50. header("Content-type: image/png");
  51. imagePng($final_image);
  52. ?>
wookieb
Tak. Ale na przyszłość zapoznaj się z Temat: SQL Injection Insertion i nie pytaj o rzeczy z serii "wywołałem funkcje, czy aby na pewno dobrze?"
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.