php用户自定过滤非法sql注入字符串函数

  1. function uc_addslashes($string, $force = 0, $strip = false) {
  2. !defined('magic_quotes_gpc') && define('magic_quotes_gpc', get_magic_quotes_gpc());
  3. if(!magic_quotes_gpc || $force) {
  4. if(is_array($string)) {
  5. foreach($string as $key => $val) {
  6. $string[$key] = uc_addslashes($val, $force, $strip);
  7. }
  8. } else {
  9. $string = addslashes($strip ? strips教程lashes($string) : $string);
  10. }
  11. }
  12. return $string;
  13. }
  14. if(!function_exists('daddslashes')) {
  15. function daddslashes($string, $force = 0) {
  16. return uc_addslashes($string, $force);
  17. }
  18. }
  19. //php 过滤函数应用实例phpfensi.com
  20. $get = $_get;
  21. $g = uc_addslashes($get, $force = 0, $strip = false);
  22. //过滤post提交数据
  23. $post = $_post;
  24. $p = uc_addslashes($post, $force = 0, $strip = false);