관리 메뉴

웹개발자의 기지개

[PHP] SQL injection 방지 함수 본문

PHP

[PHP] SQL injection 방지 함수

http://portfolio.wonpaper.net 2021. 6. 16. 10:27

최상위에 인클루드해서 쓰면 된다.

 

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?
if!get_magic_quotes_gpc() )
{
    if( is_array($_GET) )
    {
        while( list($k$v= each($_GET) )
        {
            if( is_array($_GET[$k]) )
            {
                while( list($k2$v2= each($_GET[$k]) )
                {
                    $_GET[$k][$k2= addslashes($v2);
                }
                @reset($_GET[$k]);
            }
            else
            {
                $_GET[$k= addslashes($v);
            }
        }
        @reset($_GET);
    }
 
    if( is_array($_POST) )
    {
        while( list($k$v= each($_POST) )
        {
            if( is_array($_POST[$k]) )
            {
                while( list($k2$v2= each($_POST[$k]) )
                {
                    $_POST[$k][$k2= addslashes($v2);
                }
                @reset($_POST[$k]);
            }
            else
            {
                $_POST[$k= addslashes($v);
            }
        }
        @reset($_POST);
    }
 
    if( is_array($_COOKIE) )
    {
        while( list($k$v= each($_COOKIE) )
        {
            if( is_array($_COOKIE[$k]) )
            {
                while( list($k2$v2= each($_COOKIE[$k]) )
                {
                    $_COOKIE[$k][$k2= addslashes($v2);
                }
                @reset($_COOKIE[$k]);
            }
            else
            {
                $_COOKIE[$k= addslashes($v);
            }
        }
        @reset($_COOKIE);
    }
}
?>
cs
Comments