php 快速查找数据库的恶意代码入门实例

内容摘要
这篇文章主要为大家详细介绍了php 快速查找数据库的恶意代码入门实例,具有一定的参考价值,可以用来参考一下。

对php快速查找数据库中的恶意代码对此感兴趣的朋友,看看idc笔记
文章正文

这篇文章主要为大家详细介绍了php 快速查找数据库的恶意代码入门实例,具有一定的参考价值,可以用来参考一下。

对php快速查找数据库中的恶意代码对此感兴趣的朋友,看看idc笔记做的技术笔记!数据库被输入恶意代码,为了保证你的数据库的安全,你必须得小心去清理。有了下面一个超级方便的功能,即可快速清除数据库恶意代码。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<code class="php">
/**
 * php快速查找数据库中的恶意代码
 *
 * @param
 * @author 五一二笔记网: www.idcnote.com
 **/
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教程(www.idcnote.com)   ***/</code>

注:关于php 快速查找数据库的恶意代码入门实例的内容就先介绍到这里,更多相关文章的可以留意

代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!