欢迎光临
我们一直在努力

防止SQL注入的函数。-ASP教程,数据库相关

建站超值云服务器,限时71元/月

作者:loster(oicq:181306) [如果转载,请勿删除此信息,谢谢]

函数名:s_request()

辅助函数:r_reader()

作用:过滤非法字符,防止sql注入。

参数:s_str:被传入的变量的名,类型:字符串

返回值:过滤后的值。

***************************************************************************

const c_sqlstr=",count,user,user,count,1=1,and,2=2" 需要过滤的字符串序列,每个字符串之间用“,”分隔

dim reader

function r_reader(r_str,f_str)

dim i

if r_str="" or f_str="" then

exit function

end if

reader=split(r_str,f_str)

for i=0 to ubound(reader,1)

reader(i)=cstr(trim(reader(i)))

next

r_reader=ubound(reader,1)

end function

function s_request(s_str)

dim temp,i

if s_str="" then

exit function

end if

temp=request(s_str)

for i=0 to r_reader(c_sqlstr,",")

temp=replace(temp,cstr(reader(i)),"")

next

temp=replace(temp,chr(34),"")

s_request=cstr(trim(temp))

erase reader

end function

用法:

原来的例如这样的语句:

a=request("a")

现在写成:

a=s_request("a")

即可实现非法字符串过滤。

当然,你也可以写成这样:

function s_request(s_str)

dim temp,i,temp1

if s_str="" then

exit function

end if

temp=cstr(request(s_str))

temp1=temp

for i=0 to r_reader(c_sqlstr,",")

temp=replace(temp,cstr(reader(i)),"")

if temp1<>temp then

response.write ("请不要输入非法字符!")

response.end

end if

next

temp=replace(temp,chr(34),"")

s_request=cstr(trim(temp))

erase reader

end function

这样,可以返回一个错误报告。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 防止SQL注入的函数。-ASP教程,数据库相关
分享到: 更多 (0)