当前位置: 移动技术网 > IT编程>开发语言>PHP > php快速查找数据库中恶意代码的方法

php快速查找数据库中恶意代码的方法

2018年06月25日  | 移动技术网IT编程  | 我要评论
本文实例讲述了php快速查找数据库中恶意代码的方法。分享给大家供大家参考。具体如下: 数据库被输入恶意代码,为了保证你的数据库的安全,你必须得小心去清理。有了下面一个超级

本文实例讲述了php快速查找数据库中恶意代码的方法。分享给大家供大家参考。具体如下:

数据库被输入恶意代码,为了保证你的数据库的安全,你必须得小心去清理。有了下面一个超级方便的功能,即可快速清除数据库恶意代码。

function cleaninput($input) {
 $search = array(
  '@]*?>.*?@si', // strip out javascript
  '@<[\/\!]*?[^<>]*?>@si', // strip out html tags
  '@
]*?>.*?
@siu', // strip style tags properly
  '@@' // strip multi-line comments
 );
  $output = preg_replace($search, '', $input);
  return $output;
 }
function sanitize($input) {
  if (is_array($input)) {
    foreach($input as $var=>$val) {
      $output[$var] = sanitize($val);
    }
  }
  else {
    if (get_magic_quotes_gpc()) {
      $input = stripslashes($input);
    }
    $input = cleaninput($input);
    $output = mysql_real_escape_string($input);
  }
  return $output;
}
// usage:
$bad_string = "hi! it's a good day!";
$good_string = sanitize($bad_string);
// $good_string returns "hi! it\'s a good day!"
// also use for getting post/get variables
$_post = sanitize($_post);
$_get = sanitize($_get);

希望本文所述对大家的php程序设计有所帮助。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网