Maison  >  Article  >  php教程  >  php防注入代码方法,过滤所有GET POST

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

WBOY
WBOYoriginal
2016-05-25 16:40:481729parcourir

这里我们是告诉各位朋友关于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;
}


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:php防止网站被攻击办法 Article suivant:php sql 防注入代码