Home > Backend Development > PHP Tutorial > A good general anti-injection program for PHP

A good general anti-injection program for PHP

WBOY
Release: 2016-07-25 09:03:55
Original
868 people have browsed it
  1. function jk1986_checksql()

  2. {
  3. $bad_str = "and|select|update|'|delete|insert|*";
  4. $bad_Array = explode("|" ,$bad_str);
  5. /**Filter Get parameters **/
  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('Weird characters, please do not try to inject them into this site! Author: Jk1986 QQ:414028660');location.href='index.php';</script> ";
  13. exit();
  14. }
  15. }
  16. }

  17. /**Filter Post parameters **/

  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('Weird characters, please do not try to inject this Stop! Author:Jk1986 QQ:414028660');location.href='index.php';</script>";
  25. exit();
  26. }
  27. }
  28. }

  29. / **Filter Cookies Parameters **/

  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 "
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template