Home > Backend Development > PHP Tutorial > php防注入,表单提交值转义的实现详解_php技巧

php防注入,表单提交值转义的实现详解_php技巧

WBOY
Release: 2016-05-17 09:01:57
Original
1035 people have browsed it

在开发时,我们要注意防止sql注入,所以在对表单提交过来的值要做相应的处理,才可以把数据更新到数据库里
php横扫千军函数。任何值都可以传过来转换

复制代码 代码如下:

function quotes($content)    
{    
    //如果magic_quotes_gpc=Off,那么就开始处理    
    if (!get_magic_quotes_gpc()) {    
        //判断$content是否为数组 
        if (is_array($content)) {    
            //如果$content是数组,那么就处理它的每一个单无    
            foreach ($content as $key=>$value) {    
                $content[$key] = addslashes($value);    
            }    
        } else {    
            //如果$content不是数组,那么就仅处理一次    
            addslashes($content);    
        }    
    } else {    
        //如果magic_quotes_gpc=On,那么就不处理    
    }    
    //返回$content    
    return $content;

显示的时候要用 stripslashes ()去掉反斜杠
stripslashes()了,它能把addslashes()处理时自动加上去的(反斜杠)\去掉
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template