在开发时,我们要注意防止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()处理时自动加上去的(反斜杠)\去掉

相关文章:

  • 2022-12-23
  • 2021-12-08
  • 2021-08-27
  • 2021-08-16
  • 2022-12-23
  • 2021-06-24
  • 2021-10-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案