Discuz教程网

asp终极防范SQL注入漏洞

[复制链接]
authicon dly 发表于 2011-9-8 20:22:23 | 显示全部楼层 |阅读模式
下面给出4个函数,足够你抵挡一切SQL注入漏洞!读懂代码,你就能融会贯通。

注意要对所有的request对象进行过滤:包括 request.cookie, request.ServerVariables 等等容易被忽视的对象:
  1. function killn(byval s1) '过滤数值型参数
  2. if not isnumeric(s1) then
  3. killn=0
  4. else
  5. if s1<0 or s1>2147483647 then
  6. killn=0
  7. else
  8. killn=clng(s1)
  9. end if
  10. end if
  11. end function

  12. function killc(byval s1) 过滤货币型参数
  13. if not isnumeric(s1) then
  14. killc=0
  15. else
  16. killc=formatnumber(s1,2,-1,0,0)
  17. end if
  18. end function

  19. function killw(byval s1) '过滤字符型参数
  20. if len(s1)=0 then
  21. killw=""
  22. else
  23. killw=trim(replace(s1,"'",""))
  24. end if
  25. end function

  26. function killbad(byval s1) 过滤所有危险字符,包括跨站脚本
  27. If len(s1) = 0 then
  28. killbad=""
  29. else
  30. killbad = trim(replace(replace(replace(replace(replace(replace(replace(replace(s1,Chr(10), "<br>"), Chr(34), """), ">", ">"), "<", "<"), "&", "&"),chr(39),"'"),chr(32)," "),chr(13),""))
  31. end if
  32. end function
复制代码



上一篇:asp简单生成静态的方法(模板标签替换)
下一篇:asp无组件生成验证码 GIF图片格式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 19:13

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表