首页 > 开发 > PHP > 正文

php防注入代码方法,过滤所有GET POST

2024-05-04 21:58:54
字体:
来源:转载
供稿:网友

这里我们是告诉各位朋友关于php防注入代码方法,过滤所有GET POST,因为大多数据都是能过get post 方法注入,当然还有files.

  1. /* 过滤所有GET过来变量 */  
  2. foreach ($_GET as $get_key=>$get_var)  
  3. {  
  4. if (is_numeric($get_var)) {  
  5. $get[strtolower($get_key)] = get_int($get_var);  
  6. else {  
  7. $get[strtolower($get_key)] = get_str($get_var);  
  8. }  
  9. }  
  10. /* 过滤所有POST过来的变量 */  
  11. foreach ($_POST as $post_key=>$post_var)  
  12. {  
  13. if (is_numeric($post_var)) {  
  14. $post[strtolower($post_key)] = get_int($post_var);  
  15. else {  
  16. $post[strtolower($post_key)] = get_str($post_var);  
  17. }  
  18. }  
  19. /* 过滤函数 */  
  20. //整型过滤函数  
  21. function get_int($number)  
  22. {  
  23. return intval($number);  
  24. }  
  25. //字符串型过滤函数  
  26. function get_str($string)  
  27. //开源代码Vevb.com 
  28. if (!get_magic_quotes_gpc()) {  
  29. return addslashes($string);  
  30. }  
  31. return $string;  

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表