首頁  >  文章  >  php教程  >  php防注入代码方法,过滤所有GET POST

php防注入代码方法,过滤所有GET POST

WBOY
WBOY原創
2016-05-25 16:40:481729瀏覽

这里我们是告诉各位朋友关于php防注入代码方法,过滤所有GET POST,因为大多数据都是能过get post 方法注入,当然还有files.

<?php
/* 过滤所有GET过来变量 */
foreach ($_GET as $get_key => $get_var) {
    if (is_numeric($get_var)) {
        $get[strtolower($get_key) ] = get_int($get_var);
    } else {
        $get[strtolower($get_key) ] = get_str($get_var);
    }
}
/* 过滤所有POST过来的变量 */
foreach ($_POST as $post_key => $post_var) {
    if (is_numeric($post_var)) {
        $post[strtolower($post_key) ] = get_int($post_var);
    } else {
        $post[strtolower($post_key) ] = get_str($post_var);
    }
}
/* 过滤函数 */
//整型过滤函数
function get_int($number) {
    return intval($number);
}
//字符串型过滤函数
function get_str($string) {
    if (!get_magic_quotes_gpc()) {
        return addslashes($string);
    }
    return $string;
}


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn