当前位置: 代码迷 >> ASP >> 怎么过滤单引号?
  详细解决方案

怎么过滤单引号?

热度:217   发布时间:2012-03-04 11:13:33.0
如何过滤单引号??
一个过滤函数..

Function   SafeRequest(ParaName,ParaType)
    Dim   ParaValue
    ParaValue=trim(Request(ParaName))
    If   ParaType=1   then
            If   not   isNumeric(ParaValue)   then
                Response.write   " <font   color=red> 系统出错!!! </font> "
                Response.end
                End   if
      Else
          ParaValue=replace(ParaValue, " ' ", " ' ' ")
    End   if    
    SafeRequest=ParaValue
End   function

其中的   ParaValue=replace(ParaValue, " ' ", " ' ' ")  
这个过滤是不是正确的啊??
为什么这样就能过滤了单引号啊??

------解决方案--------------------
把单个的单引号替换成连续成对的单引号么,比较常用的防注技巧
------解决方案--------------------
replace(str, " ' ", " ")
------解决方案--------------------
response.write ParaValue
放到sql一看,原来这样就防注了
------解决方案--------------------
INSERT INTO 表名 (列名) VALUES ( 'test 'test ')
INSERT INTO 表名 (列名) VALUES ( 'test ' 'test ')
你试试看这两个语句就知道了
  相关解决方案