仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 533|回复: 8
打印 上一主题 下一主题

[学习教程] ASP教程之ASP过滤SQL不法字符并格局化html代码

[复制链接]
谁可相欹 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:20:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
使用cdonts,可以发送、查看邮件,实现webmail的功能。结合wsh,可以实现对nt主机的管理,如nt用户管理、iis虚拟主机设置、exchange邮箱设置等等,就像管理本地机一样方便。sql<%
functionchangechr(str)
changechr=replace(replace(replace(replace(str,"<","<"),">",">"),chr(13),"<br>"),"","")
changechr=replace(replace(replace(replace(changechr,"[sayyes]","<divalign=center><imgsrc="),"","<b>"),"[red]","<fontcolor=CC0000>"),"[big]","<fontsize=7>")
changechr=replace(replace(replace(replace(changechr,"[/sayyes]","></img></div>"),"
","</b>"),"[/red]","</font>"),"[/big]","</font>")
endfunction
过滤SQL不法字符并格局化html代码
functionReplace_Text(fString)
ifisnull(fString)then
Replace_Text=""
exitfunction
else
fString=trim(fString)
fString=replace(fString,"","")
fString=replace(fString,";",";")
fString=replace(fString,"--","―")
fString=server.htmlencode(fString)
Replace_Text=fString
endif
endfunction
会员公布的各类信息过滤
FunctionReplace_Text(fString)
IfNotIsNull(fString)Then
fString=trim(fString)
fString=replace(fString,";",";")分号过滤
fString=replace(fString,"--","――")--过滤
fString=replace(fString,"%20","")特别字符过滤
fString=replace(fString,"==","")==过滤
fString=replace(fString,">",">")
fString=replace(fString,"<","<")
fString=Replace(fString,CHR(32),"")
fString=Replace(fString,CHR(9),"")
fString=Replace(fString,CHR(34),""")
fString=Replace(fString,CHR(39),"")单引号过滤
fString=Replace(fString,CHR(13),"")
fString=Replace(fString,CHR(10)&CHR(10),"</P><P>")
fString=Replace(fString,CHR(10),"<BR>")
Replace_Text=fString
EndIf
EndFunction
过滤SQL不法字符
FunctioncheckStr(Chkstr)
dimStr:Str=Chkstr
ifisnull(Str)then
checkStr=""
exitFunction
else
Str=replace(Str,"","")
Str=replace(Str,";","")
Str=replace(Str,"--","")
checkStr=Str
endif
EndFunction
检测传送的参数是不是为数字型
FunctionChkrequest(Para)
Chkrequest=False
IfNot(IsNull(Para)OrTrim(Para)=""OrNotIsNumeric(Para))Then
Chkrequest=True
EndIf
EndFunction
检测传送的参数是不是为日期型
FunctionChkrequestdate(Para)
Chkrequestdate=False
IfNot(IsNull(Para)OrTrim(Para)=""OrNotIsDate(Para))Then
Chkrequestdate=True
EndIf
EndFunction
失掉以后页面的地点
FunctionGetUrl()
OnErrorResumeNext
DimstrTemp
IfLCase(Request.ServerVariables("HTTPS"))="off"Then
strTemp="http://"
Else
strTemp="https://"
EndIf
strTemp=strTemp&CheckStr(Request.ServerVariables("SERVER_NAME"))
IfRequest.ServerVariables("SERVER_PORT")80ThenstrTemp=strTemp&":"&CheckStr(Request.ServerVariables("SERVER_PORT"))
strTemp=strTemp&CheckStr(Request.ServerVariables("URL"))
IfTrim(Request.QueryString)""ThenstrTemp=strTemp&"?"&CheckStr(Trim(Request.QueryString))
GetUrl=strTemp
EndFunction
FunctionCheckReferer()反省用户是不是在扫瞄器里输出了本页的地点
DimsReferer,Icheck
CheckReferer=True
sReferer=Request.ServerVariables("HTTP_REFERER")
ServerIP=Request.ServerVariables("LOCAL_ADDR")
Icheck=InStr(sReferer,"ServerIP")
IfIcheck=0Then
CheckReferer=False
EndIf
EndFunction
日期格局化
FunctionFormatDate(DT,tp)
dimY,M,D
Y=Year(DT)
M=month(DT)
D=Day(DT)
ifM<10thenM="0"&M
ifD<10thenD="0"&D
selectcasetp
case1FormatDate=Y&"年"&M&"月"&D&"日"
case2FormatDate=Y&"-"&M&"-"&D
endselect
EndFunction
不同意内部提交数据的选择
FunctionChkPost()
dimHTTP_REFERER,SERVER_NAME
dimserver_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)
ifmid(server_v1,8,len(server_v2))server_v2then
chkpost=false
else
chkpost=true
endif
EndFunction
机关上传图片文件名随机数
functionMakedownName()
dimfname
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
endfunction
Email检测
functionIsValidEmail(email)
dimnames,name,i,c
IsValidEmail=true
names=Split(email,"@")
ifUBound(names)1then
IsValidEmail=false
exitfunction
endif
foreachnameinnames
ifLen(name)<=0then
IsValidEmail=false
exitfunction
endif
fori=1toLen(name)
c=Lcase(Mid(name,i,1))
ifInStr("abcdefghijklmnopqrstuvwxyz_-.",c)<=0andnotIsNumeric(c)then
IsValidEmail=false
exitfunction
endif
next
ifLeft(name,1)="."orRight(name,1)="."then
IsValidEmail=false
exitfunction
endif
next
ifInStr(names(1),".")<=0then
IsValidEmail=false
exitfunction
endif
i=Len(names(1))-InStrRev(names(1),".")
ifi2andi3then
IsValidEmail=false
exitfunction
endif
ifInStr(email,"..")>0then
IsValidEmail=false
endif
endfunction
Jmail邮件发送
FunctionSendJmail(Email,Topic,MailBody)
DimJMail
onerrorresumenext
SetJMail=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.AddRecipientEmail
JMail.AddHeader"Originating-IP",GBL_IPAddress
IfJMail.Execute()=falseThen
SendJmail=0
Else
SendJmail=1
EndIf
JMail.Close
SetJMail=Nothing
EndFunction
分页
FunctionlistPages(LinkFile)
ifnot(rs.eofandrs.bof)then
gopage=currentpage
totalpage=n
blockPage=Int((gopage-1)/10)*10+1
ifinstr(linkfile,"?page=")>0orinstr(linkfile,"&page=")>0then
pos=instr(linkfile,"page=")-2
linkfile=left(linkfile,pos)
endif

IfLCase(Request.ServerVariables("HTTPS"))="off"Then
strTemp="http://"
Else
strTemp="https://"
EndIf
strTemp=strTemp&CheckStr(Request.ServerVariables("SERVER_NAME"))
IfRequest.ServerVariables("SERVER_PORT")80ThenstrTemp=strTemp&":"&CheckStr(Request.ServerVariables("SERVER_PORT"))
strTemp=strTemp&CheckStr(Request.ServerVariables("URL"))
lenstrTemp=len(strTemp)+1
ifinstr(left(linkfile,lenstrTemp),"?")>0then

ifblockPage=1Then
Response.Write"<spandisabled>【←前10页</span>"
Else
Response.Write("<spandisabled>【</span><ahref="&LinkFile&"&page="&blockPage-10&">←前10页</a>")
EndIf
i=1
DoUntili>10orblockPage>n
IfblockPage=int(gopage)Then
Response.Write("<fontcolor=#FF0000>[<b>"&blockPage&"</b>]</font>")
Else
Response.Write("<ahref="&LinkFile&"&page="&blockPage&">["&blockPage&"]</a>")
EndIf
blockPage=blockPage+1
i=i+1
Loop
ifblockPage>totalpageThen
Response.Write"<spandisabled>后10页→】"
Else
Response.Write("<ahref="&LinkFile&"&page="&blockPage&">后10页→</a><spandisabled>】")
EndIf
response.write"间接到第"
response.write"<selectonchange=if(this.options[this.selectedIndex].value!=){location=this.options[this.selectedIndex].value;}>"
fori=1tototalpage
response.write"<optionvalue="&LinkFile&"&page="&i&""
ifi=gopagethenresponse.write"selected"
response.write">"&i&"</option>"
next
response.write"</select>"
response.write"页<Br><Br>"

else

ifblockPage=1Then
Response.Write"<spandisabled>【←前10页</span>"
Else
Response.Write("<spandisabled>【</span><ahref="&LinkFile&"?page="&blockPage-10&">←前10页</a>")
EndIf
i=1
DoUntili>10orblockPage>n
IfblockPage=int(gopage)Then
Response.Write("<fontcolor=#FF0000>[<b>"&blockPage&"</b>]</font>")
Else
Response.Write("<ahref="&LinkFile&"?page="&blockPage&">["&blockPage&"]</a>")
EndIf
blockPage=blockPage+1
i=i+1
Loop
ifblockPage>totalpageThen
Response.Write"<spandisabled>后10页→】"
Else
Response.Write("<ahref="&LinkFile&"?page="&blockPage&">后10页→</a><spandisabled>】")
EndIf
response.write"间接到第"
response.write"<selectonchange=if(this.options[this.selectedIndex].value!=){location=this.options[this.selectedIndex].value;}>"
fori=1tototalpage
response.write"<optionvalue="&LinkFile&"?page="&i&""
ifi=gopagethenresponse.write"selected"
response.write">"&i&"</option>"
next
response.write"</select>"
response.write"页<Br><Br>"

EndIf

Startinfo=((gopage-1)*msg_per_page)+1
Endinfo=gopage*msg_per_page
ifEndinfo>totalrecthenEndinfo=totalrec
Response.Write("共"&totalrec&"条信息以后显现第"&Startinfo&"-"&Endinfo&"条每页"&msg_per_page&"条信息共"&n&"页")
endif
EndFunction
分页2
FunctionlistPages2(LinkFile)
ifnot(rs.eofandrs.bof)then
gopage=currentpage
totalpage=n
blockPage=Int((gopage-1)/10)*10+1

IfLCase(Request.ServerVariables("HTTPS"))="off"Then
strTemp="http://"
Else
strTemp="https://"
EndIf
strTemp=strTemp&CheckStr(Request.ServerVariables("SERVER_NAME"))
IfRequest.ServerVariables("SERVER_PORT")80ThenstrTemp=strTemp&":"&CheckStr(Request.ServerVariables("SERVER_PORT"))
strTemp=strTemp&CheckStr(Request.ServerVariables("URL"))
lenstrTemp=len(strTemp)+1
ifinstr(left(linkfile,lenstrTemp),"?")>0then

ifblockPage=1Then
Response.Write"<spandisabled>前10页</span>"
Else
Response.Write("<ahref="&LinkFile&"&page="&blockPage-10&">前10页</a>")
EndIf
i=1
DoUntili>10orblockPage>n
IfblockPage=int(gopage)Then
Response.Write("<fontcolor=#FF0000><b>"&blockPage&"</b></font>")
Else
Response.Write("<ahref="&LinkFile&"&page="&blockPage&">"&blockPage&"</a>")
EndIf
blockPage=blockPage+1
i=i+1
Loop
ifblockPage>totalpageThen
Response.Write"<spandisabled>后10页"
Else
Response.Write("<ahref="&LinkFile&"&page="&blockPage&">后10页</a><spandisabled>")
EndIf
response.write"间接到第"
response.write"<selectonchange=if(this.options[this.selectedIndex].value!=){location=this.options[this.selectedIndex].value;}>"
fori=1tototalpage
response.write"<optionvalue="&LinkFile&"&page="&i&""
ifi=gopagethenresponse.write"selected"
response.write">"&i&"</option>"
next
response.write"</select>"
response.write"页<Br><Br>"

else

ifblockPage=1Then
Response.Write"<spandisabled>【←前10页</span>"
Else
Response.Write("<spandisabled>【</span><ahref="&LinkFile&"?page="&blockPage-10&">←前10页</a>")
EndIf
i=1
DoUntili>10orblockPage>n
IfblockPage=int(gopage)Then
Response.Write("<fontcolor=#FF0000>[<b>"&blockPage&"</b>]</font>")
Else
Response.Write("<ahref="&LinkFile&"?page="&blockPage&">["&blockPage&"]</a>")
EndIf
blockPage=blockPage+1
i=i+1
Loop
ifblockPage>totalpageThen
Response.Write"<spandisabled>后10页→】"
Else
Response.Write("<ahref="&LinkFile&"?page="&blockPage&">后10页→</a><spandisabled>】")
EndIf
response.write"间接到第"
response.write"<selectonchange=if(this.options[this.selectedIndex].value!=){location=this.options[this.selectedIndex].value;}>"
fori=1tototalpage
response.write"<optionvalue="&LinkFile&"?page="&i&""
ifi=gopagethenresponse.write"selected"
response.write">"&i&"</option>"
next
response.write"</select>"
response.write"页<Br><Br>"

EndIf

Startinfo=((gopage-1)*msg_per_page)+1
Endinfo=gopage*msg_per_page
ifEndinfo>totalrecthenEndinfo=totalrec
Response.Write("共"&totalrec&"条信息以后显现第"&Startinfo&"-"&Endinfo&"条每页"&msg_per_page&"条信息共"&n&"页")
endif
EndFunction
判别文件范例是不是及格
FunctionCheckFileExt(FileExt)
DimForumUpload,i
ForumUpload="gif,jpg,bmp,jpeg,png"
ForumUpload=Split(ForumUpload,",")
CheckFileExt=False
Fori=0toUBound(ForumUpload)
IfLCase(FileExt)=Lcase(Trim(ForumUpload(i)))Then
CheckFileExt=True
ExitFunction
EndIf
Next
EndFunction
格局后缀
FunctionFixName(UpFileExt)
IfIsEmpty(UpFileExt)ThenExitFunction
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","")
EndFunction
文件Content-Type判别
FunctionCheckFileType(FileType)
CheckFileType=False
IfLeft(Cstr(Lcase(Trim(FileType))),6)="image/"ThenCheckFileType=True
EndFunction
%>
SQLServer是基于服务器端的中型的数据库,可以适合大容量数据的应用,在功能上管理上也要比Access要强得多。在处理海量数据的效率,后台开发的灵活性,可扩展性等方面强大。
若天明 该用户已被删除
沙发
发表于 2015-1-19 09:07:40 | 只看该作者
以HTML语言整合(HTML负责界面上,ASP则负责功能上)形成一个B/S(浏览器/服务器)模式的网页程序。
精灵巫婆 该用户已被删除
板凳
发表于 2015-1-25 21:31:40 | 只看该作者
ASP主要是用好六个对象,其实最主要的是用好其中两个:response和request,就可以随心所欲地控制网页变换和响应用户动作了。
小女巫 该用户已被删除
地板
发表于 2015-2-4 04:40:42 | 只看该作者
掌握asp的特性而且一定要知道为什么。
分手快乐 该用户已被删除
5#
发表于 2015-2-9 15:50:41 | 只看该作者
ASP主要是用好六个对象,其实最主要的是用好其中两个:response和request,就可以随心所欲地控制网页变换和响应用户动作了。
深爱那片海 该用户已被删除
6#
发表于 2015-2-27 09:07:15 | 只看该作者
ASP也是这几种脚本语言中最简单易学的开发语言。但ASP也是这几种语言中唯一的一个不能很好支持跨平台的语言。  因为ASP脚本语言非常简单,因此其代码也简单易懂,结合HTML代码,可快速地完成网站的应用程序。
飘灵儿 该用户已被删除
7#
发表于 2015-3-9 00:44:21 | 只看该作者
我就感觉到ASP和一些常用的数据库编程以及软件工程方面的思想是非常重要的。我现在也在尝试自己做网页,这其中就用到了ASP,我想它的作用是可想而知的。
若相依 该用户已被删除
8#
发表于 2015-3-16 19:50:11 | 只看该作者
Session:这个存储跟客户端会话过程的数据,默认20分钟失效
小妖女 该用户已被删除
9#
发表于 2015-3-23 01:25:26 | 只看该作者
学习ASP其实应该上升到如何学习程序设计这种境界,其实学习程序设计又是接受一种编程思想。比如ASP如何学习,你也许在以前的学习中碰到过。以下我仔细给你说几点:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-12-24 04:19

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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