HOME
BBS
深山帮帮欢迎您,您可以注册或者
qq登录只需一步,快速开始
深山旅行社网站管理系统开发完成,欢迎各位网友测试! 点这里测试
565449214 给站长留言
订阅本栏目 RSS您所在的位置: 深山工作室 > ASP学习 > 正文

ASP过滤SQL中的非法字符并格式化相关的html代码

天极网 2008-3-15 20:34:15 深山行者 字体:  浏览 5187 我要评论

 

 

以下是引用片段:

<%
function changechr(str)
changechr=replace(replace(replace(replace(str,"<","&lt;"),">","&gt;"),chr(13),"<br>")," ","&nbsp;")
changechr=replace(replace(replace(replace(changechr,"[sayyes]","<div align=center><img src="),"[b]","<b>"),"[red]","<font color=CC0000>"),"[big]","<font size=7>")
changechr=replace(replace(replace(replace(changechr,"[/sayyes]","></img></div>"),"[/b]","</b>"),"[/red]","</font>"),"[/big]","</font>")
end function

'过滤SQL非法字符并格式化html代码
function Replace_Text(fString)
if isnull(fString) then
Replace_Text=""
exit function
else
fString=trim(fString)
fString=replace(fString,"'","''")
fString=replace(fString,";",";")
fString=replace(fString,"--","—")
fString=server.htmlencode(fString)
Replace_Text=fString
end if
end function

'会员发布的各种信息过滤
'Function Replace_Text(fString)
'If Not IsNull(fString) Then
'fString = trim(fString)
'fString = replace(fString, ";", ";")     '分号过滤
'fString = replace(fString, "--", "——") '--过滤
'fString = replace(fString, "%20", "")    '特殊字符过滤
'fString = replace(fString, "==", "")     '==过滤
'fString = replace(fString, ">", "&gt;")
'fString = replace(fString, "<", "&lt;")
'fString = Replace(fString, CHR(32), " ")   '&nbsp;
'fString = Replace(fString, CHR(9), " ")    '&nbsp;
'fString = Replace(fString, CHR(34), "&quot;")
'fString = Replace(fString, CHR(39), "&#39;") '单引号过滤
'fString = Replace(fString, CHR(13), "")
'fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
'fString = Replace(fString, CHR(10), "<BR> ")
'Replace_Text = fString
'End If
'End Function

'过滤SQL非法字符
Function checkStr(Chkstr)
dim Str:Str=Chkstr
if isnull(Str) then
   checkStr = ""
   exit Function
else
   Str=replace(Str,"'","")
   Str=replace(Str,";","")
   Str=replace(Str,"--","")
   checkStr=Str
end if
End Function

'检测传递的参数是否为数字型
Function Chkrequest(Para)
Chkrequest=False
If Not (IsNull(Para) Or Trim(Para)="" Or Not IsNumeric(Para)) Then
    Chkrequest=True
End If
End Function

'检测传递的参数是否为日期型
Function Chkrequestdate(Para)
Chkrequestdate=False
If Not (IsNull(Para) Or Trim(Para)="" Or Not IsDate(Para)) Then
    Chkrequestdate=True
End If
End Function

'得到当前页面的地址
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & CheckStr(Request.ServerVariables("SERVER_NAME"))
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & CheckStr(Request.ServerVariables("SERVER_PORT"))
strTemp = strTemp & CheckStr(Request.ServerVariables("URL"))
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & CheckStr(Trim(Request.QueryString))
GetUrl = strTemp 
End Function

'Function CheckReferer()   '检查用户是否在浏览器里输入了本页的地址
'     Dim sReferer, Icheck
'     CheckReferer = True
'     sReferer = Request.ServerVariables("HTTP_REFERER")
'     ServerIP = Request.ServerVariables("LOCAL_ADDR")
'     Icheck = InStr(sReferer, "ServerIP")
'     If Icheck = 0 Then
'     CheckReferer = False
'     End If
'End Function

'日期格式化
Function FormatDate(DT,tp)
dim Y,M,D
Y=Year(DT)
M=month(DT)
D=Day(DT)
if M<10 then M="0"&M
if D<10 then D="0"&D
select case tp
case 1 FormatDate=Y&"年"&M&"月"&D&"日"
case 2 FormatDate=Y&"-"&M&"-"&D
end select
End Function

'不允许外部提交数据的选择
Function ChkPost()
     dim HTTP_REFERER,SERVER_NAME
dim server_v1,server_v2
chkpost=false
     SERVER_NAME=CheckStr(Request.ServerVariables("SERVER_NAME"))
HTTP_REFERER=CheckStr(Request.ServerVariables("HTTP_REFERER"))
server_v1=Cstr(HTTP_REFERER)
server_v2=Cstr(SERVER_NAME)
if mid(server_v1,8,len(server_v2))<>server_v2 then
   chkpost=false
else
   chkpost=true
end if
End Function

'构造上传图片文件名随机数
function MakedownName()
dim fname
fname = now()
fname = replace(fname,"-","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
fname = int(fname) + int((10-1+1)*Rnd + 1)
MakedownName=fname
end function

'Email检测
function IsValidEmail(email)
dim names, name, i, c
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
    IsValidEmail = false
    exit function
end if
for each name in names
    if Len(name) <= 0 then
      IsValidEmail = false
      exit function
    end if
    for i = 1 to Len(name)
      c = Lcase(Mid(name, i, 1))
      if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
        IsValidEmail = false
        exit function
      end if
    next
    if Left(name, 1) = "." or Right(name, 1) = "." then
       IsValidEmail = false
       exit function
    end if
next
if InStr(names(1), ".") <= 0 then
    IsValidEmail = false
    exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
    IsValidEmail = false
    exit function
end if
if InStr(email, "..") > 0 then
    IsValidEmail = false
end if
end function

'Jmail邮件发送
Function SendJmail(Email,Topic,MailBody)

Dim JMail
on error resume next
Set JMail = Server.CreateObject("JMail.SMTPMail")
JMail.LazySend             = true
JMail.silent             = true
JMail.Charset             = "gb2312"
JMail.ContentType       = "text/html"
JMail.Sender             = "wemaster@alibaba.info" '我们网站自己的邮箱
JMail.ReplyTo             = "wemaster@alibaba.info" '我们网站自己的邮箱
JMail.SenderName       = "阿里爸爸邮件发送"
JMail.Subject             = Topic
JMail.SimpleLayout       = true
JMail.Body             = MailBody
JMail.Priority             = 3
JMail.AddRecipient Email
JMail.AddHeader "Originating-IP", GBL_IPAddress
If JMail.Execute() = false Then
   SendJmail = 0
Else
   SendJmail = 1
End If
JMail.Close
Set JMail = Nothing

End Function

'分页
Function listPages(LinkFile)
    if not (rs.eof and rs.bof) then
gopage=currentpage
totalpage=n
blockPage=Int((gopage-1)/10)*10+1
' if instr(linkfile,"?page=")>0 or instr(linkfile,"&page=")>0 then
' pos=instr(linkfile,"page=")-2
' linkfile=left(linkfile,pos)
' end if

If LCase(Request.ServerVariables("HTTPS")) = "off" Then
     strTemp = "http://"
     Else
     strTemp = "https://"
     End If
     strTemp = strTemp & CheckStr(Request.ServerVariables("SERVER_NAME"))
     If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & CheckStr(Request.ServerVariables("SERVER_PORT"))
     strTemp = strTemp & CheckStr(Request.ServerVariables("URL"))
     lenstrTemp=len(strTemp)+1
if instr(left(linkfile,lenstrTemp),"?")>0 then

if blockPage = 1 Then
   Response.Write "<span disabled>【←前10页</span>&nbsp;"
Else
   Response.Write("<span disabled>【</span><a href=" & LinkFile & "&page="&blockPage-10&">←前10页</a>&nbsp;")
End If
    i=1
    Do Until i > 10 or blockPage > n
     If blockPage=int(gopage) Then
   Response.Write("<font color=#FF0000>[<b>"&blockPage&"</b>]</font>")
Else
   Response.Write(" <a href=" & LinkFile & "&page="&blockPage&">["&blockPage&"]</a> ")
     End If
     blockPage=blockPage+1
     i = i + 1
     Loop
if blockPage > totalpage Then
   Response.Write "&nbsp;<span disabled>后10页→】"
Else
   Response.Write("&nbsp;<a href=" & LinkFile & "&page="&blockPage&">后10页→</a><span disabled>】")
End If
response.write" 直接到第 "
response.write"<select onchange=if(this.options[this.selectedIndex].value!=''){location=this.options[this.selectedIndex].value;}>"
     for i=1 to totalpage
     response.write"<option value='" & LinkFile & "&page=" & i & "'"
     if i=gopage then response.write"selected"
     response.write">"&i&"</option>"
     next
     response.write"</select>"
     response.write" 页<Br><Br>"

else

if blockPage = 1 Then
   Response.Write "<span disabled>【←前10页</span>&nbsp;"
Else
   Response.Write("<span disabled>【</span><a href=" & LinkFile & "?page="&blockPage-10&">←前10页</a>&nbsp;")
End If
    i=1
    Do Until i > 10 or blockPage > n
     If blockPage=int(gopage) Then
   Response.Write("<font color=#FF0000>[<b>"&blockPage&"</b>]</font>")
Else
   Response.Write(" <a href=" & LinkFile & "?page="&blockPage&">["&blockPage&"]</a> ")
     End If
     blockPage=blockPage+1
     i = i + 1
     Loop
if blockPage > totalpage Then
   Response.Write "&nbsp;<span disabled>后10页→】"
Else
   Response.Write("&nbsp;<a href=" & LinkFile & "?page="&blockPage&">后10页→</a><span disabled>】")
End If
response.write" 直接到第 "
response.write"<select onchange=if(this.options[this.selectedIndex].value!=''){location=this.options[this.selectedIndex].value;}>"
     for i=1 to totalpage
     response.write"<option value='" & LinkFile & "?page=" & i & "'"
     if i=gopage then response.write"selected"
     response.write">"&i&"</option>"
     next
     response.write"</select>"
     response.write" 页<Br><Br>"

End If

Startinfo=((gopage-1)*msg_per_page)+1
Endinfo=gopage*msg_per_page
if Endinfo>totalrec then Endinfo=totalrec
   Response.Write("&nbsp;&nbsp;共 "&totalrec&" 条信息 当前显示第 "&Startinfo&" - "&Endinfo&" 条 每页 "&msg_per_page&" 条信息 共 "&n&" 页")
end if
End Function

'分页2
Function listPages2(LinkFile)
    if not (rs.eof and rs.bof) then
gopage=currentpage
totalpage=n
blockPage=Int((gopage-1)/10)*10+1

If LCase(Request.ServerVariables("HTTPS")) = "off" Then
     strTemp = "http://"
     Else
     strTemp = "https://"
     End If
     strTemp = strTemp & CheckStr(Request.ServerVariables("SERVER_NAME"))
     If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & CheckStr(Request.ServerVariables("SERVER_PORT"))
     strTemp = strTemp & CheckStr(Request.ServerVariables("URL"))
     lenstrTemp=len(strTemp)+1
if instr(left(linkfile,lenstrTemp),"?")>0 then

if blockPage = 1 Then
   Response.Write "<span disabled>前10页</span>&nbsp;"
Else
   Response.Write("<a href=" & LinkFile & "&page="&blockPage-10&">前10页</a>&nbsp;")
End If
    i=1
    Do Until i > 10 or blockPage > n
     If blockPage=int(gopage) Then
   Response.Write("<font color=#FF0000><b>"&blockPage&"</b></font>")
Else
   Response.Write(" <a href=" & LinkFile & "&page="&blockPage&">"&blockPage&"</a> ")
     End If
     blockPage=blockPage+1
     i = i + 1
     Loop
if blockPage > totalpage Then
   Response.Write "&nbsp;<span disabled>后10页"
Else
   Response.Write("&nbsp;<a href=" & LinkFile & "&page="&blockPage&">后10页</a><span disabled>")
End If
response.write" 直接到第 "
response.write"<select onchange=if(this.options[this.selectedIndex].value!=''){location=this.options[this.selectedIndex].value;}>"
     for i=1 to totalpage
     response.write"<option value='" & LinkFile & "&page=" & i & "'"
     if i=gopage then response.write"selected"
     response.write">"&i&"</option>"
     next
     response.write"</select>"
     response.write" 页<Br><Br>"

else

if blockPage = 1 Then
   Response.Write "<span disabled>【←前10页</span>&nbsp;"
Else
   Response.Write("<span disabled>【</span><a href=" & LinkFile & "?page="&blockPage-10&">←前10页</a>&nbsp;")
End If
    i=1
    Do Until i > 10 or blockPage > n
     If blockPage=int(gopage) Then
   Response.Write("<font color=#FF0000>[<b>"&blockPage&"</b>]</font>")
Else
   Response.Write(" <a href=" & LinkFile & "?page="&blockPage&">["&blockPage&"]</a> ")
     End If
     blockPage=blockPage+1
     i = i + 1
     Loop
if blockPage > totalpage Then
   Response.Write "&nbsp;<span disabled>后10页→】"
Else
   Response.Write("&nbsp;<a href=" & LinkFile & "?page="&blockPage&">后10页→</a><span disabled>】")
End If
response.write" 直接到第 "
response.write"<select onchange=if(this.options[this.selectedIndex].value!=''){location=this.options[this.selectedIndex].value;}>"
     for i=1 to totalpage
     response.write"<option value='" & LinkFile & "?page=" & i & "'"
     if i=gopage then response.write"selected"
     response.write">"&i&"</option>"
     next
     response.write"</select>"
     response.write" 页<Br><Br>"

End If

Startinfo=((gopage-1)*msg_per_page)+1
Endinfo=gopage*msg_per_page
if Endinfo>totalrec then Endinfo=totalrec
   Response.Write("&nbsp;&nbsp;共 "&totalrec&" 条信息 当前显示第 "&Startinfo&" - "&Endinfo&" 条 每页 "&msg_per_page&" 条信息 共 "&n&" 页")
end if
End Function

'判断文件类型是否合格
Function CheckFileExt(FileExt)
Dim ForumUpload,i
ForumUpload="gif,jpg,bmp,jpeg,png"
ForumUpload=Split(ForumUpload,",")
CheckFileExt=False
For i=0 to UBound(ForumUpload)
   If LCase(FileExt)=Lcase(Trim(ForumUpload(i))) Then
    CheckFileExt=True
    Exit Function
   End If
Next
End Function
'格式后缀
Function FixName(UpFileExt)
If IsEmpty(UpFileExt) Then Exit Function
FixName = Lcase(UpFileExt)
FixName = Replace(FixName,Chr(0),"")
FixName = Replace(FixName,".","")
FixName = Replace(FixName,"asp","")
FixName = Replace(FixName,"asa","")
FixName = Replace(FixName,"aspx","")
FixName = Replace(FixName,"cer","")
FixName = Replace(FixName,"cdx","")
FixName = Replace(FixName,"htr","")
End Function
'文件Content-Type判断
Function CheckFileType(FileType)
CheckFileType = False
If Left(Cstr(Lcase(Trim(FileType))),6)="image/" Then CheckFileType = True
End Function
%>

 

加入收藏
打印本页
当前标签:asp
Ads loading...
相关阅读
( 2018-6-21 17:35:47 )ASP操作access或sqlserver数据库的函数库
( 2018-5-29 11:27:36 )asp采用access数据库搜索信息时因为日文片假名问题提示“Microsoft JET Database Engine 错误80040e14”的解决方法
( 2018-5-19 9:23:42 )asp利用dateadd获得上个月、本月、下个月的第一天和最后一天
( 2018-5-18 16:58:25 )asp随机显示字符长度与类型(可随机显示数字、小写字母、大写字母,可以做为随机密码使用)
( 2018-5-14 10:35:46 )ASP版通过身份证信息获取对应的生日性别年龄
( 2018-5-9 10:29:10 )ASP网站打开特别卡 提示:msxml3.dll 错误 '80072ee2' /LM/W3SVC/670931603/Root/global.asa解决办法
( 2018-4-10 11:26:02 )asp通过多次获得来取得用户的真实IP
( 2018-3-20 15:13:15 )asp利用sina提供的ip库端口来获得当前IP所有的地区,所在国,所在省,所在市,在线解析json
共有0条关于《ASP过滤SQL中的非法字符并格式化相关的html代码》的评论
发表评论
正在加载评论……
返回顶部发表评论
呢 称:
表 情:
内 容:
评论内容:不能超过 400 字,需审核,请自觉遵守互联网相关政策法规。
验证码: 验证码 
深山工作室网友评论声明,请自觉遵守互联网相关政策法规。

您发布的评论即表示同意遵守以下条款:
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家、社会、集体和公民的合法权益;
二、不得发布国家法律、法规明令禁止的内容;互相尊重,对自己在本站的言论和行为负责;
三、本站对您所发布内容拥有处置权。

Ads loading...
更多信息>>栏目类别选择
rss学习
个人空间
网站设计
网站公告
下载
photoshop学习
ASP学习
DIV+CSS学习
SEO搜索引擎忧化
java学习
HTML学习
网站信息
网站类信息
更多>>同类信息
批量删除access字段里面fld.Properties.Delete
ASP操作access或sqlserver数据库的函数库
asp中求两个数的百分比(利用百分比函数FormatPercent就可以自带%的符号)
asp利用sql操作数据表、数据库的一些方法
rs操作数据表记录集对象的方法
[转载]中国行政区划数据(省市区街道)
ASP版通过身份证信息获取对应的生日性别年龄
ASP网站打开特别卡 提示:msxml3.dll 错误 '80072ee2' /LM/W3SVC/670931603/Root/global.asa解决办法
Ads loading...
更多>>最新添加文章
批量删除access字段里面fld.Properties.Delete
ASP操作access或sqlserver数据库的函数库
asp采用access数据库搜索信息时因为日文片假名问题提示“Microsoft JET Database Engine 错误80040e14”的解决方法
asp中求两个数的百分比(利用百分比函数FormatPercent就可以自带%的符号)
asp利用sql操作数据表、数据库的一些方法
rs操作数据表记录集对象的方法
asp利用dateadd获得上个月、本月、下个月的第一天和最后一天
asp随机显示字符长度与类型(可随机显示数字、小写字母、大写字母,可以做为随机密码使用)
  • 业务 QQ:565449214
  • 手机:139 6134 7334
更多>>随机抽取信息
超级实用且不花哨的js代码大全( 8 )
利用CSS设置网页滚动条颜色
Word图片导出方法
CSS的十八般技巧
超强的中间自适应,左右固定,有许多值得学习的地方
深山行者留言系统V2.2 (简称留言板V2.2)
asp中求两个数的百分比(利用百分比函数FormatPercent就可以自带%的符号)
性感的CSS菜单(Menus)
Ads loading...