整理了一个editplus的剪辑文件(ASP方面的内容)
#title=asp常用语法及函数
#info
asp常用的一些语法及自定义函数
#sort=n
#t= ===asp常用语法===
#t=============================
#t=数据库相关
#t= 连接access数据库
<%
dim dbname,conn
dbname"^!" '定义数据库路径及名称
set conn = server.createobject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(dbname)
%>
#t= 连接ms sql数据库
<%
dim conn
set conn=server.createobject("adodb.connection")
conn.open "provider=sqloledb;data source=sql服务器名称或ip地址;uid=数据库登录帐号;pwd=数据库密码;database=数据库名称"
%>
#t= 建立记录集
set ^!=server.createobject("adodb.recordset")
#t= 执行sql命令
rs.open sql,conn,1,1
#t= 执行sql命令
conn.execute("^!")
#t= rs直接执行sql命令
set rs = conn.execute("^!")
#t= 关闭记录集
rs.close
set rs=nothing
#t= 关闭数据库
conn.close
set conn=nothing
#t=============================
#t=servervariables相关
#t= 取上一页地址
request.servervariables("http_referer")
#t= 取服务器的名称1
request.servervariables("server_name")
#t= 取服务器的名称2
request.servervariables("http_host")
#t= 取服务器ip
request.servervariables("local_addr")
#t= 取用户ip
request.servervariables("remote_host")
#t= 取用户真实ip1
request.servervariables("remote_addr")
#t= 取用户真实ip函数
function getrealip()
getrealip = request.servervariables("http_x_forwarded_for")
if(getrealip = "")then getrealip = request.servervariables("remote_addr")
end function
#t= 取服务器端口
request.servervariables("server_port")
#t= 取服务器操作系统
request.servervariables("os")
#t= 取服务器的绝对路径
request.servervariables("appl_physical_path")
#t= 取本文件的绝对路径1
requet.servervariables("path_translated")
#t= 取本文件的绝对路径2
server.mappath(request.servervariables("script_name"))
#t= 取本文件的相对路径1
request.servervariables("url")
#t= 取本文件的相对路径2
request.servervariables("script_name")
#t= 取本文件的相对路径3
request.servervariables("path_info")
#t= 取地址栏后的参数
request.servervariables("query_string")
#t= 取服务器系统信息
request.servervariables("http_user_agent")
#t= 服务器组件检测
<%
function isobjinstalled(strclassstring)
on error resume next
isobjinstalled = false
err = 0
dim xtestobj
set xtestobj = server.createobject(strclassstring)
if(0 = err)then isobjinstalled = true
set xtestobj = nothing
err = 0
end function
'if(isobjinstalled("persits.upload")=true)then
' response.write "支持aspupload组件"
'else
' response.write "不支持aspupload组件"
'end if
%>
#t= 取客户端语言环境
^!request.servervariables("http_accept_language")
#t= 取客户端信息:http_user_agent
^!request.servervariables("http_user_agent")
#t= 取表单(form)值元素值
request.form("^!")
#t= 取url传递的值
request.querystring("^!")
#t= 取完整url地址
function geturl()
geturl="http://"&request.servervariables("server_n ... .servervariables("url")
if(request.servervariables("query_string")<>"")then geturl=geturl&"?"& request.servervariables("query_string")
end function
#t=============================
#t=自定义函数
#t= 过滤html字符
<%
'过滤html字符函数
function htmlencode(str)
if(str <> "")then
str = replace(str, "&", "&")
str = replace(str, ">", ">")
str = replace(str, "<", "<")
str = replace(str, chr(32), " ")
str = replace(str, chr(9), " ")
str = replace(str, chr(34), """)
str = replace(str, chr(39), "'")
str = replace(str, chr(13), "")
str = replace(str, chr(10) & chr(10), "</p><p>")
str = replace(str, chr(10), "<br>")
str = replace(str, chr(255), " ")
end if
htmlencode = str
end function
%>
#t= 检测上页是否从本站提交
<%
'检测上页是否从本站提交
'返回:true,false
'===============================================================
function isselfrefer()
dim shttp_referer, sserver_name
shttp_referer = cstr(request.servervariables("http_referer"))
sserver_name = cstr(request.servervariables("server_name"))
if(mid(shttp_referer, 8, len(sserver_name)) = sserver_name)then
isselfrefer = true
else
isselfrefer = false
end if
end function
%>
#t= 清除所有html标记
<%
'清除html标记
function striphtml(htmlstr)
dim regex
set regex = new regexp
regex.ignorecase = true
regex.global = true
regex.pattern = "<.+?>"
htmlstr = regex.replace(htmlstr,"")
htmlstr = replace(htmlstr, "<","<")
htmlstr = replace(htmlstr, ">",">")
htmlstr = replace(htmlstr,chr(10),"")
htmlstr = replace(htmlstr,chr(13),"")
striphtml = htmlstr
set regex = nothing
end function
%>
#t= 取字符串长度
<%
'求字符串长度函数
function getlength(str)
dim length
for i=1 to len(str)
if(asc(mid(str,i,1))<0 or asc(mid(str,i,1))>256)then
length=length+2
else
length=length+1
end if
next
getlength=length
end function
%>
#t= 截取指定长度字符串
<%
'截取指定长度的字符串,多余的用...代替
function strleft(str,strlen)
if(str = "")then
strleft = ""
exit function
end if
dim l,t,c,i
str = replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
l=len(str)
t=0
for i=1 to l
c=abs(asc(mid(str,i,1)))
if(c>255)then
t=t+2
else
t=t+1
end if
if(t>strlen)then
strleft = left(str,i) & "..."
exit for
else
strleft = str
end if
next
strleft = replace(replace(replace(replace(strleft," "," "),chr(34),"""),">",">"),"<","<")
end function
%>
#t= 获取安全的提交参数
<%
'===============================================================
'sql injection check
'函数功能:过滤字符参数中的单引号,对于数字参数进行判断,如果不是数值类型,则赋值0
'参数意义:str ---- 要过滤的参数
'strtype ---- 参数类型,分为字符型和数字型,字符型为"s",数字型为"i"
'===============================================================
function checkstr(str,strtype)
dim strtmp
strtmp = ""
if(strtype ="s")then
strtmp = replace(trim(str),"'","''")
elseif(strtype="i")then
if(isnumeric(str)=false)then str=false
strtmp = str
else
strtmp = str
end if
checkstr= strtmp
end function
%>
#t= 过滤不良字符(badword)
<%
'过滤不良字符(badwords)
function chkbadwords(fstring)
dim badwords,bwords,i
badwords = "我操|操你|操他|你妈的|他妈的|狗|杂种|屄|屌|王八|强奸|做爱|处女|泽民|*|法伦|*|*"
if(not(isnull(badwords) or isnull(fstring)))then
bwords = split(badwords, "|")
for i = 0 to ubound(bwords)
fstring = replace(fstring, bwords(i), string(len(bwords(i)),"*"))
next
chkbadwords = fstring
end if
end function
%>
#t= 生成随机自定义长度密码
<%
'生成随机自定义长度密码
function makepassword(maxlen)
dim strnewpass
dim whatsnext, upper, lower, intcounter
randomize
for intcounter = 1 to maxlen
whatsnext = int((1 - 0 + 1) * rnd + 0)
if(whatsnext = 0)then
'character
upper = 90
lower = 65
else
upper = 57
lower = 48
end if
strnewpass = strnewpass & chr(int((upper - lower + 1) * rnd + lower))
next
makepassword = strnewpass
end function
'response.write makepassword(8)
%>
#t= 填入textarea时保持格式inhtml
<%
'===============================================================
'去除html格式,用于从数据库中取出值填入输入框时
'注意:value="?"这边一定要用双引号
'===============================================================
function inhtml(str)
dim stemp
stemp = str
inhtml = ""
if isnull(stemp) = true then
exit function
end if
stemp = replace(stemp, "&", "&")
stemp = replace(stemp, "<br>",chr(13))
stemp = replace(stemp, "<", "<")
stemp = replace(stemp, ">", ">")
stemp = replace(stemp, """, chr(34))
inhtml = stemp
end function
%>
#t= 正则表表达式验证函数
<%
'正则表表达式验证函数 patrn-正则表达式 strng-需要验证的字符串
'===============================================================
function regexptest(patrn, strng)
dim regex, retval ' 建立变量。
set regex = new regexp ' 建立正则表达式。
regex.pattern = patrn ' 设置模式。
regex.ignorecase = false ' 设置是否区分大小写。
retval = regex.test(strng) ' 执行搜索测试。
regexptest = retval '返回值,不符合就返回false,符合为true
set regex = nothing
end function
%>
#t= 生成随机字符串
<%
'生成随机字符串
function rndcode()
dim codeset,amountset
codeset = "0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
amountset = 62 ' 文字数量
randomize
dim vcode(10), vcodes,i
for i = 0 to 9
vcode(i) = int(rnd * amountset)
vcodes = vcodes & mid(codeset, vcode(i) + 1, 1)
next
rndcode=vcodes
end function
%>
#t=============================
#t=fso相关操作
#t= 判断目录是否存在
<%
function isfloderexist(strfoldername)
set fso=server.createobject("scripting.filesystemobject")
if(fso.folderexists(strfoldername))then
isfloderexist = true
else
isfloderexist = false
end if
set fso=nothing
end function
%>
#t= 创建目录
<%
function createfolder(strfoldername)
set fso=server.createobject("scripting.filesystemobject")
if(fso.folderexists(strfoldername) = false)then
fso.createfolder(strfoldername)
end if
set fso=nothing
end function
%>
#t= 删除目录
<%
function deletefolder(strfoldername)
set fso=server.createobject("scripting.filesystemobject")
if(fso.folderexists(strfoldername))then
fso.deletefolder(strfoldername)
end if
set fso=nothing
end function
%>
#t= 判断文件是否存在
<%
function isfileexist(strfilename)
set fso=server.createobject("scripting.filesystemobject")
if(fso.fileexists(strfilename))then
isfileexist = true
else
isfileexist = false
end if
set fso=nothing
end function
%>
#t= 删除文件
<%
function deletefile(strfilename)
set fso=server.createobject("scripting.filesystemobject")
if(fso.fileexists(strfilename))then
fso.deletefile(strfilename)
end if
set fso=nothing
end function
%>
#t=============================
#t= asp小偷常用的几个函数
<%
function bytetostr(vin)
dim strreturn,i,thischarcode,innercode,hight8,low8,nextcharcode
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if(thischarcode < &h80)then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytetostr = strreturn
end function
function gethttppagecontent(url,method,sendstr)
dim retrieval
set retrieval = server.createobject("microsoft.xmlhttp")
with retrieval
.open method, url, false ,"" ,""
.setrequestheader "content-type","application/x-www-form-urlencoded"
.send(sendstr)
gethttppagecontent = .responsebody
end with
set retrieval = nothing
gethttppagecontent=bytetostr(gethttppagecontent)
end function
function regexptext(strng,regstr)
dim regex,match,matches,retstr
set regex = new regexp
regex.pattern = regstr
regex.ignorecase = true
regex.global = true
set matches = regex.execute(strng)
for each match in matches
retstr = retstr & regex.replace(match.value,"$1") & ","
next
regexptext = retstr
set regex=nothing
end function
function streambytestobstr(strbody, codebase)
dim objstream
set objstream = server.createobject("adodb.stream")
with objstream
.type = 1
.mode = 3
.open
.write strbody
.position = 0
.type = 2
.charset = codebase
streambytestobstr = .readtext
.close
end with
set objstream = nothing
end function
%>
下一篇: 另类的文件上传解决方案