Heim  >  Artikel  >  Backend-Entwicklung  >  一个不错的php通用防注入程序

一个不错的php通用防注入程序

WBOY
WBOYOriginal
2016-07-25 09:03:55797Durchsuche
  1. function jk1986_checksql()

  2. {
  3. $bad_str = "and|select|update|'|delete|insert|*";
  4. $bad_Array = explode("|",$bad_str);
  5. /** 过滤Get参数 **/
  6. foreach ($bad_Array as $bad_a)
  7. {
  8. foreach ($_GET as $g)
  9. {
  10. if (substr_count(strtolower($g),$bad_a) > 0)
  11. {
  12. echo "<script>alert('诡异字符,请不要尝试注入本站! 作者:Jk1986 QQ:414028660');location.href='index.php';</script>";
  13. exit();
  14. }
  15. }
  16. }
  17. /** 过滤Post参数 **/

  18. foreach ($bad_Array as $bad_a)

  19. {
  20. foreach ($_POST as $p)
  21. {
  22. if (substr_count(strtolower($p),$bad_a) > 0)
  23. {
  24. echo "<script>alert('诡异字符,请不要尝试注入本站! 作者:Jk1986 QQ:414028660');location.href='index.php';</script>";
  25. exit();
  26. }
  27. }
  28. }
  29. /** 过滤Cookies参数 **/

  30. foreach ($bad_Array as $bad_a)

  31. {
  32. foreach ($_COOKIE as $co)
  33. {
  34. if (substr_count(strtolower($co),$bad_a) > 0)
  35. {
  36. echo "<script>alert('诡异字符,请不要尝试注入本站! 作者:Jk1986 QQ:414028660');location.href='index.php';</script>";
  37. exit();
  38. }
  39. }
  40. }
  41. }
  42. ?>
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn