<%
'-------------------------------------
'天楓asp class v1.0,集常用asp函數(shù)于一體
'天楓版權(quán)所有http://52515.net
'qq:76994859 email:chenshaobo@gmail.com
'所有功能函數(shù)名如下:
' strlength(str) 取得字符串長度
' cutstr(str,strlen) 字符串長度切割
' checkisempty(tstr) 檢測(cè)是否為空
' isinteger(para) 整數(shù)檢驗(yàn)
' checkname(str) 名字字符校驗(yàn)
' checkpassword(str) 密碼檢驗(yàn)
' checkemail(email) 郵箱格式檢驗(yàn)
' alert(msg,gourl) 彈出對(duì)話框提示
' goback(str1,str2,isback) 出錯(cuò)信息提示
' suc(str1,str2,url) 操作成功信息提示
' chkpost() 檢測(cè)是否站外提交表單
' psql() 防止sql注入
' filtratehtmlcode(str) 防止生成html
' htmlcode(str) 過濾html
' replacehtml(tstr) 清濾html
' getip() 獲取客戶端ip
' getbrowser 獲取客戶端瀏覽器信
' getsystem 獲取客戶端操作系統(tǒng)
' geturl() 獲取當(dāng)前頁面url包含參數(shù)
' curl() 獲取當(dāng)前頁面url
' getextend 取得文件擴(kuò)展名
' checkexist(table,fieldname,fieldcontent,isblur) 檢測(cè)某個(gè)表中某個(gè)字段的內(nèi)容是否存在
' getnum(table,fieldname,resulttype,args) 檢測(cè)某個(gè)表某個(gè)字段有多少條,最大值 ,最小值等
' getfoldersize(folderpath) 計(jì)算某個(gè)文件夾的大小
' getfilesize(filename) 計(jì)算某個(gè)文件的大小
' isobjinstalled(strclassstring) 檢測(cè)組件是否安裝
' sendmail jmail發(fā)送郵件
' responsecookies 寫入cookies
' cleancookies 清除cookies
' gettimeover 取得程序頁面執(zhí)行時(shí)間
' formatsize 大小格式化
' formattime 時(shí)間格式化
' zodiac 取得生肖
' constellation 取得星座
'-------------------------------------
class cls_fun
'--------字符處理--------------------------
'****************************************************
'函數(shù)名:strlength
'作 用:取得字符串長度(漢字為2)
'參 數(shù):str ----字符串內(nèi)容
'返回值:字符串長度
'****************************************************
public function strlength(str)
dim rep,lens,i
set rep=new regexp
rep.global=true
rep.ignorecase=true
rep.pattern="[\u4e00-\u9fa5\uf900-\ufa2d]"
for each i in rep.execute(str)
lens=lens+1
next
set rep=nothing
lens=lens + len(str)
strlength=lens
end function
'****************************************************
'函數(shù)名:cutstr
'作 用:字符串長度切割,超過顯示省略號(hào)
'參 數(shù):str ----字符串內(nèi)容
' strlen ------要顯示的長度
'返回值:切割后字符串內(nèi)容
'****************************************************
public function cutstr(str,strlen)
dim l,t,i,c
if str="" then
cutstr=""
exit function
end if
str=replace(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
cutstr=left(str,i) & "..."
exit for
else
cutstr=str
end if
next
cutstr=replace(replace(replace(replace(replace(cutstr," "," "),chr(34),"""),">",">"),"<","<"),"|","|")
end function
'--------------系列驗(yàn)證----------------------------
'****************************************************
'函數(shù)名:checkisempty
'作 用:檢查是否為空
'參 數(shù):tstr ----字符串
'返回值:true不為空,false為空
'****************************************************
public function checkisempty(tstr)
checkisempty=false
if isnull(tstr) or tstr="" then exit function
dim str,re
str=tstr
set re=new regexp
re.ignorecase =true
re.global=true
str= replace(str, vbnewline, "")
str = replace(str, chr(9), "")
str = replace(str, " ", "")
str = replace(str, " ", "")
re.pattern="]*)>"
str =re.replace(str,"94kk")
re.pattern="<(.[^>]*)>"
str=re.replace(str,"")
set re=nothing
if str<>"" then checkisempty=true
end function
'****************************************************
'函數(shù)名:isinteger
'作 用:整數(shù)檢驗(yàn)
'參 數(shù):tstr ----字符
'返回值:true是整數(shù),false不是整數(shù)
'****************************************************
public function isinteger(para)
on error resume next
dim str
dim l,i
if isnull(para) then
isinteger=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isinteger=false
exit function
end if
l=len(str)
for i=1 to l
if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
isinteger=false
exit function
end if
next
isinteger=true
if err.number<>0 then err.clear
end function
'****************************************************
'函數(shù)名:checkname
'作 用:名字字符檢驗(yàn)
'參 數(shù):str ----字符串
'返回值:true無誤,false有誤
'****************************************************
public function checkname(str)
checkname=true
dim rep,pass
set rep=new regexp
rep.global=true
rep.ignorecase=true
'匹配字母、數(shù)字、下劃線、漢字且必須以字母或下劃線或漢字開始
rep.pattern="^[a-za-z_u4e00-\u9fa5][\w\u4e00-\u9fa5]+$"
set pass=rep.execute(str)
if pass.count=0 then checkname=false
set rep=nothing
end function
'****************************************************
'函數(shù)名:checkpassword
'作 用:密碼檢驗(yàn)
'參 數(shù):str ----字符串
'返回值:true無誤,false有誤
'****************************************************
public function checkpassword(str)
dim pass
checkpassword=true
if str <> "" then
dim rep
set rep = new regexp
rep.global = true
rep.ignorecase = true
'匹配字母、數(shù)字、下劃線、點(diǎn)號(hào)
rep.pattern="[a-za-z0-9_\.]+$"
pass=rep.test(str)
set rep=nothing
if not pass then checkpassword=false
end if
end function
'****************************************************
'函數(shù)名:checkemail
'作 用:郵箱格式檢測(cè)
'參 數(shù):str ----email地址
'返回值:true無誤,false有誤
'****************************************************
public function checkemail(email)
checkemail=true
dim rep
set rep = new regexp
rep.pattern="([\.a-za-z0-9_-]){2,10}@([a-za-z0-9_-]){2,10}(\.([a-za-z0-9]){2,}){1,4}$"
pass=rep.test(email)
set rep=nothing
if not pass then checkemail=false
end function
'--------------信息提示----------------------------
'****************************************************
'函數(shù)名:alert
'作 用:彈出對(duì)話框提示
'參 數(shù):msg ----對(duì)話框信息
' gourl ----提示后轉(zhuǎn)向哪里
'返回值:無
'****************************************************
public function alert(msg,gourl)
msg = replace(msg,"'","\'")
if gourl="" then
gourl="history.go(-1);"
else
gourl="window.location.href='"&gourl&"'"
end if
response.write ("")
response.end
end function
'****************************************************
'函數(shù)名:goback
'作 用:錯(cuò)誤信息提示
'參 數(shù):str1 ----信息提示標(biāo)題
' str2 ----信息提示內(nèi)容
' isback ----是否顯示返回
'返回值:無
'****************************************************
public function goback(str1,str2,isback)
if str1="" then str1="錯(cuò)誤信息"
if str2="" then str2="請(qǐng)?zhí)顚懲暾靥铐?xiàng)目"
if isback="" then
str2=str2&" 返回重填"
else
str2=str2
end if
response.write"
"
response.end
end function
'****************************************************
'函數(shù)名:suc
'作 用:成功提示信息
'參 數(shù):str1 ----信息提示標(biāo)題
' str2 ----信息提示內(nèi)容
' url ----返回地址
'返回值:無
'****************************************************
public function suc(str1,str2,url)
if str1="" then str1="操作成功"
if str2="" then str2="成功的完成這次操作!"
if url="" then url="javascript:history.go(-1)"
str2=str2&" 返回繼續(xù)管理"
response.write"
"
end function
'--------------安全處理----------------------------
'****************************************************
'函數(shù)名:chkpost
'作 用:禁止站外提交表單
'返回值:true站內(nèi)提交,flase站外提交
'****************************************************
public function chkpost()
dim url1,url2
chkpost=true
url1=cstr(request.servervariables("http_referer"))
url2=cstr(request.servervariables("server_name"))
if mid(url1,8,len(url2))<>url2 then
chkpost=false
exit function
end if
end function
'****************************************************
'函數(shù)名:psql
'作 用:防止sql注入
'返回值:為空則無注入,不為空則注入并返回注入的字符
'****************************************************
public function psql()
psql=""
badwords= "'防''防;防and防exec防insert防select防update防delete防count防*防%防chr防m(xù)id防m(xù)aster防truncate防char防declare防|"
badword=split(badwords,"防")
if request.form<>"" then
for each tf_post in request.form
for i=0 to ubound(badword)
if instr(lcase(request.form(tf_post)),badword(i))>0 then
psql=badword(i)
exit function
end if
next
next
end if
if request.querystring<>"" then
for each tf_get in request.querystring
for i=0 to ubound(badword)
if instr(lcase(request.querystring(tf_get)),badword(i))>0 then
psql=badword(i)
exit function
end if
next
next
end if
end function
'****************************************************
'函數(shù)名:filtratehtmlcode
'作 用:防止生成html代碼
'參 數(shù):str ----字符串
'****************************************************
public function filtratehtmlcode(str)
if not isnull(str) and str<>"" then
str=replace(str,chr(9),"")
str=replace(str,"|","|")
str=replace(str,chr(39),"'")
str=replace(str,"<","<")
str=replace(str,">",">")
str = replace(str, chr(13),"")
str = replace(str, chr(10),"")
filtratehtmlcode=str
end if
end function
'函數(shù)名:htmlcode
'作 用:過濾html標(biāo)簽
'參 數(shù):str ----字符串
'****************************************************
public function htmlcode(str)
if not isnull(str) and str<>"" then
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), "")
str = replace(str, "script", "script")
htmlcode = str
end if
end function
'****************************************************
'函數(shù)名:replacehtml
'作 用:清理html
'參 數(shù):tstr ----字符串
'****************************************************
public function replacehtml(tstr)
dim str,re
str=tstr
set re=new regexp
re.ignorecase =true
re.global=true
re.pattern="<(p|\/p|br)>"
str=re.replace(str,vbnewline)
re.pattern="]*src(=| )(.[^>]*)>"
str=re.replace(str,"")
re.pattern="<(.[^>]*)>"
str=re.replace(str,"")
set re=nothing
replacehtml=str
end function
'---------------獲取客戶端和服務(wù)端的一些信息-------------------
'****************************************************
'函數(shù)名:getip
'作 用:獲取客戶端ip地址
'返回值:客戶端ip地址
'****************************************************
public function getip()
dim temp
temp = request.servervariables("http_x_forwarded_for")
if temp = "" or isnull(temp) or isempty(temp) then temp = request.servervariables("remote_addr")
if instr(temp,"'")>0 then temp="0.0.0.0"
getip = temp
end function
'****************************************************
'函數(shù)名:getbrowser
'作 用:獲取客戶端瀏覽器信息
'返回值:客戶端瀏覽器信息
'****************************************************
public function getbrowser()
info=request.servervariables(http_user_agent)
if instr(info,"netcaptor 6.5.0")>0 then
browser="netcaptor 6.5.0"
elseif instr(info,"myie 3.1")>0 then
browser="myie 3.1"
elseif instr(info,"netcaptor 6.5.0rc1")>0 then
browser="netcaptor 6.5.0rc1"
elseif instr(info,"netcaptor 6.5.pb1")>0 then
browser="netcaptor 6.5.pb1"
elseif instr(info,"msie 5.5")>0 then
browser="internet explorer 5.5"
elseif instr(info,"msie 6.0")>0 then
browser="internet explorer 6.0"
elseif instr(info,"msie 6.0b")>0 then
browser="internet explorer 6.0b"
elseif instr(info,"msie 5.01")>0 then
browser="internet explorer 5.01"
elseif instr(info,"msie 5.0")>0 then
browser="internet explorer 5.00"
elseif instr(info,"msie 4.0")>0 then
browser="internet explorer 4.01"
else
browser="其它"
end if
end function
'****************************************************
'函數(shù)名:getsystem
'作 用:獲取客戶端操作系統(tǒng)
'返回值:客戶端操作系統(tǒng)
'****************************************************
function getsystem()
info=request.servervariables(http_user_agent)
if instr(info,"nt 5.1")>0 then
system="windows xp"
elseif instr(info,"tel")>0 then
system="telport"
elseif instr(info,"webzip")>0 then
system="webzip"
elseif instr(info,"flashget")>0 then
system="flashget"
elseif instr(info,"offline")>0 then
system="offline"
elseif instr(info,"nt 5")>0 then
system="windows 2000"
elseif instr(info,"nt 4")>0 then
system="windows nt4"
elseif instr(info,"98")>0 then
system="windows 98"
elseif instr(info,"95")>0 then
system="windows 95"
elseif instr(info,"unix") or instr(info,"linux") or instr(info,"sunos") or instr(info,"bsd") then
system="類unix"
elseif instr(thesoft,"mac") then
system="mac"
else
system="其它"
end if
end function
'****************************************************
'函數(shù)名:geturl
'作 用:獲取url包括參數(shù)
'返回值:獲取url包括參
該文章在 2010/7/3 14:15:14 編輯過