PHP quick Way to find malicious code in a database _php tutorial

Source: Internet
Author: User

PHP quick Way to find malicious code in a database


The examples in this article describe how PHP quickly finds malicious code in a database. Share to everyone for your reference. Specific as follows:

The database is entered into malicious code, in order to keep your database secure, you have to be careful to clean up. With the following super-convenient feature, you can quickly clear the database of malicious code.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

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);

http://www.bkjia.com/PHPjc/977167.html www.bkjia.com true http://www.bkjia.com/PHPjc/977167.html techarticle PHP Quick Way to find malicious code in a database The example in this article describes how PHP quickly finds malicious code in a database. Share to everyone for your reference. The following: Database is ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.