[p]<%[br]'-------------------------------------[br]'天枫asp class v1.0,集常用asp函数于一体[br]'天枫版权所有http://52515.net[br]'qq:76994859 email:chenshaobo@gmail.com[/p]
[p]'所有功能函数名如下:[br]' strlength(str) 取得字符串长度[br]' cutstr(str,strlen) 字符串长度切割[br]' checkisempty(tstr) 检测是否为空[br]' isinteger(para) 整数检验[br]' checkname(str) 名字字符校验[br]' checkpassword(str) 密码检验[br]' checkemail(email) 邮箱格式检验[br]' alert(msg,gourl) 弹出对话框提示[br]' goback(str1,str2,isback) 出错信息提示[br]' suc(str1,str2,url) 操作成功信息提示[br]' chkpost() 检测是否站外提交表单[br]' psql() 防止sql注入[br]' filtratehtmlcode(str) 防止生成html[br]' htmlcode(str) 过滤html[br]' replacehtml(tstr) 清滤html[br]' getip() 获取客户端ip[br]' getbrowser 获取客户端浏览器信[br]' getsystem 获取客户端操作系统[br]' geturl() 获取当前页面url包含参数[br]' curl()   获取当前页面url[br]' getextend 取得文件扩展名[br]' checkexist(table,fieldname,fieldcontent,isblur) 检测某个表中某个字段的内容是否存在[br]' getnum(table,fieldname,resulttype,args) 检测某个表某个字段有多少条,最大值 ,最小值等[br]' getfoldersize(folderpath) 计算某个文件夹的大小[br]' getfilesize(filename) 计算某个文件的大小[br]' isobjinstalled(strclassstring) 检测组件是否安装[br]' sendmail jmail发送邮件[br]' responsecookies 写入cookies[br]' cleancookies 清除cookies[br]' gettimeover 取得程序页面执行时间[br]' formatsize 大小格式化[br]' formattime 时间格式化[br]' zodiac 取得生肖[br]' constellation   取得星座[br]'-------------------------------------[/p]
[p]class cls_fun[/p]
[p]'--------字符处理--------------------------[br]    [br]'****************************************************[br]'函数名:strlength[br]'作 用:取得字符串长度(汉字为2)[br]'参 数:str ----字符串内容[br]'返回值:字符串长度[br]'****************************************************[br]public function strlength(str)[br]    dim rep,lens,i[br]    set rep=new regexp[br]    rep.global=true[br]    rep.ignorecase=true[br]    rep.pattern="[\u4e00-\u9fa5\uf900-\ufa2d]"[br]    for each i in rep.execute(str)[br]     lens=lens+1[br]    next[br]    set rep=nothing[br]    lens=lens + len(str)[br]    strlength=lens[br]   end function[br]  [br]'****************************************************[br]'函数名:cutstr[br]'作 用:字符串长度切割,超过显示省略号[br]'参 数:str    ----字符串内容[br]'       strlen ------要显示的长度[br]'返回值:切割后字符串内容[br]'****************************************************[br]public function cutstr(str,strlen)[br]     dim l,t,i,c[br]     if str="" then[br]     cutstr=""[br]     exit function[br]     end if[br]     str=replace(replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<"),"|","|")[br]     l=len(str)[br]     t=0[br]     for i=1 to l[br]     c=abs(asc(mid(str,i,1)))[br]     if c>255 then[br]     t=t+2[br]     else[br]     t=t+1[br]     end if[br]     if t>=strlen then[br]     cutstr=left(str,i) & "..."[br]     exit for[br]     else[br]     cutstr=str[br]     end if[br]     next[br]     cutstr=replace(replace(replace(replace(replace(cutstr," "," "),chr(34),"""),">",">"),"<","<"),"|","|")[br]   end function[/p]
[p]'--------------系列验证----------------------------[/p]
[p]    '****************************************************[br]'函数名:checkisempty[br]'作 用:检查是否为空[br]'参 数:tstr ----字符串[br]'返回值:true不为空,false为空[br]'****************************************************[br]public function checkisempty(tstr)[br]   checkisempty=false[br]   if isnull(tstr) or tstr="" then exit function [br]   dim str,re[br]   str=tstr[br]   set re=new regexp[br]   re.ignorecase =true[br]   re.global=true[br]   str= replace(str, vbnewline, "")[br]   str = replace(str, chr(9), "")[br]   str = replace(str, " ", "")[br]   str = replace(str, " ", "")[br]   re.pattern="
![]()
]*)>"[br]   str =re.replace(str,"94kk")[br]   re.pattern="<(.[^>]*)>"[br]   str=re.replace(str,"")[br]   set re=nothing[br]   if str<>"" then checkisempty=true[br]end function[/p]
[p]    '****************************************************[br]'函数名:isinteger[br]'作 用:整数检验[br]'参 数:tstr ----字符[br]'返回值:true是整数,false不是整数[br]'****************************************************[br]public function isinteger(para)[br]     on error resume next[br]     dim str[br]     dim l,i[br]     if isnull(para) then [br]     isinteger=false[br]     exit function[br]     end if[br]     str=cstr(para)[br]     if trim(str)="" then[br]     isinteger=false[br]     exit function[br]     end if[br]     l=len(str)[br]     for i=1 to l[br]      if mid(str,i,1)>"9" or mid(str,i,1)<"0" then[br]      isinteger=false [br]      exit function[br]      end if[br]     next[br]     isinteger=true[br]     if err.number<>0 then err.clear[br]end function[br][br]    '****************************************************[br]'函数名:checkname[br]'作 用:名字字符检验 [br]'参 数:str ----字符串[br]'返回值:true无误,false有误[br]'****************************************************[br]public function checkname(str)[br]   checkname=true[br]   dim rep,pass[br]   set rep=new regexp[br]   rep.global=true[br]   rep.ignorecase=true[br]   '匹配字母、数字、下划线、汉字且必须以字母或下划线或汉字开始[br]   rep.pattern="^[a-za-z_u4e00-\u9fa5][\w\u4e00-\u9fa5]+$"[br]   set pass=rep.execute(str)[br]   if pass.count=0 then checkname=false[br]   set rep=nothing[br]end function[br][br]'****************************************************[br]'函数名:checkpassword[br]'作 用:密码检验[br]'参 数:str ----字符串[br]'返回值:true无误,false有误[br]'****************************************************[br]public function checkpassword(str)[br]   dim pass[br]   checkpassword=true[br]   if str <> "" then[br]    dim rep[br]    set rep = new regexp[br]    rep.global = true[br]    rep.ignorecase = true[br]    '匹配字母、数字、下划线、点号[br]    rep.pattern="[a-za-z0-9_\.]+$"[br]    pass=rep.test(str)[br]    set rep=nothing[br]    if not pass then checkpassword=false[br]    end if[br]end function [br][br]'****************************************************[br]'函数名:checkemail[br]'作 用:邮箱格式检测[br]'参 数:str ----email地址[br]'返回值:true无误,false有误[br]'****************************************************[br]public function checkemail(email)[br]     checkemail=true[br]   dim rep[br]   set rep = new regexp[br]   rep.pattern="([\.a-za-z0-9_-]){2,10}@([a-za-z0-9_-]){2,10}(\.([a-za-z0-9]){2,}){1,4}$"[br]   pass=rep.test(email)[br]   set rep=nothing[br]   if not pass then checkemail=false[br]end function[/p]
[p]'--------------信息提示----------------------------  [br]'****************************************************[br]'函数名:alert[br]'作 用:弹出对话框提示[br]'参 数:msg   ----对话框信息[br]'       gourl ----提示后转向哪里[br]'返回值:无[br]'****************************************************[br]    public function alert(msg,gourl)[br]   msg = replace(msg,"'","\'")[br]   if gourl="" then[br]      gourl="history.go(-1);"[br]   else[br]    gourl="window.location.href='"&gourl&"'"[br]   end if[br]   response.write ("")[br]   response.end[br]end function[/p]
[p]    '****************************************************[br]'函数名:goback[br]'作 用:错误信息提示[br]'参 数:str1   ----信息提示标题[br]'       str2   ----信息提示内容[br]'       isback ----是否显示返回[br]'返回值:无[br]'****************************************************[br]public function goback(str1,str2,isback)[br]   if str1="" then str1="错误信息"[br]   if str2="" then str2="请填写完整必填项目"[br]   if isback="" then [br]    str2=str2&" 
返回重填"[br]   else[br]    str2=str2[br]   end if[br]   response.write"
"[br]   response.end[br]end function[/p]
[p]    '****************************************************[br]'函数名:suc[br]'作 用:成功提示信息[br]'参 数:str1   ----信息提示标题[br]'       str2   ----信息提示内容[br]'       url    ----返回地址[br]'返回值:无[br]'****************************************************[br]public function suc(str1,str2,url)[br]   if str1="" then str1="操作成功"[br]   if str2="" then str2="成功的完成这次操作!"[br]   if url="" then url="javascript:history.go(-1)"[br]   str2=str2&"  
返回继续管理"[br]   response.write"
"[br]end function[br][br]'--------------安全处理---------------------------- [/p]
[p]'****************************************************[br]'函数名:chkpost[br]'作 用:禁止站外提交表单[br]'返回值:true站内提交,flase站外提交[br]'****************************************************[br]public function chkpost()[br]   dim url1,url2[br]   chkpost=true[br]   url1=cstr(request.servervariables("http_referer"))[br]   url2=cstr(request.servervariables("server_name"))[br]   if mid(url1,8,len(url2))<>url2 then[br]    chkpost=false[br]    exit function[br]   end if[br]end function[/p]
[p]'****************************************************[br]'函数名:psql[br]'作 用:防止sql注入[br]'返回值:为空则无注入,不为空则注入并返回注入的字符[br]'****************************************************[br]public function psql()[br]     psql=""[br]   badwords= "'防''防;防and防exec防insert防select防update防delete防count防*防%防chr防mid防master防truncate防char防declare防|"[br]   badword=split(badwords,"防")[br]   if request.form<>"" then[br]    for each tf_post in request.form[br]     for i=0 to ubound(badword)[br]      if instr(lcase(request.form(tf_post)),badword(i))>0 then[br]       psql=badword(i)[br]       exit function[br]      end if[br]     next[br]    next[br]   end if[br]   if request.querystring<>"" then[br]    for each tf_get in request.querystring[br]     for i=0 to ubound(badword)[br]      if instr(lcase(request.querystring(tf_get)),badword(i))>0 then[br]       psql=badword(i)[br]       exit function[br]      end if[br]     next[br]    next[br]   end if[br]end function[/p]
[p]    '****************************************************[br]'函数名:filtratehtmlcode[br]'作 用:防止生成html代码 [br]'参 数:str ----字符串[br]'****************************************************[br]public function filtratehtmlcode(str)[br]   if not isnull(str) and str<>"" then[br]    str=replace(str,chr(9),"")[br]    str=replace(str,"|","|")[br]    str=replace(str,chr(39),"'")[br]    str=replace(str,"<","<")[br]    str=replace(str,">",">")[br]    str = replace(str, chr(13),"")[br]    str = replace(str, chr(10),"")[br]    filtratehtmlcode=str[br]   end if[br]end function[/p]
[p] [/p]
[p]'函数名:htmlcode[br]'作 用:过滤html标签[br]'参 数:str ----字符串[br]'****************************************************[br]public function htmlcode(str)[br]   if not isnull(str) and str<>"" then[br]    str = replace(str, ">", ">")[br]    str = replace(str, "<", "<")[br]    str = replace(str, chr(32), " ")[br]    str = replace(str, chr(9), " ")[br]    str = replace(str, chr(34), """)[br]    str = replace(str, chr(39), "'")[br]    str = replace(str, chr(13), "")[br]    str = replace(str, chr(10), "")[br]    str = replace(str, "script", "script")[br]    htmlcode = str[br]   end if[br]end function[/p]
[p]    '****************************************************[br]'函数名:replacehtml[br]'作 用:清理html[br]'参 数:tstr ----字符串[br]'****************************************************[br]public function replacehtml(tstr)[br]   dim str,re[br]   str=tstr[br]   set re=new regexp[br]    re.ignorecase =true[br]    re.global=true[br]    re.pattern="<(p|\/p|br)>"[br]    str=re.replace(str,vbnewline)[br]    re.pattern="
]*src(=| )(.[^>]*)>"[br]    str=re.replace(str,"[img]$2[/img]")[br]    re.pattern="<(.[^>]*)>"[br]    str=re.replace(str,"")[br]    set re=nothing[br]    replacehtml=str[br]end function[/p]
[p][br]'---------------获取客户端和服务端的一些信息-------------------[/p]
[p]    '****************************************************[br]'函数名:getip[br]'作 用:获取客户端ip地址[br]'返回值:客户端ip地址[br]'****************************************************[br]    public function getip()[br]   dim temp[br]   temp = request.servervariables("http_x_forwarded_for")[br]   if temp = "" or isnull(temp) or isempty(temp) then temp = request.servervariables("remote_addr")[br]   if instr(temp,"'")>0 then temp="0.0.0.0"[br]   getip = temp[br]end function[/p]
[p]    '****************************************************[br]'函数名:getbrowser[br]'作 用:获取客户端浏览器信息[br]'返回值:客户端浏览器信息[br]'****************************************************[br]    public function getbrowser()[br]        info=request.servervariables(http_user_agent) [br]   if instr(info,"netcaptor 6.5.0")>0 then[br]    browser="netcaptor 6.5.0"[br]   elseif instr(info,"myie 3.1")>0 then[br]    browser="myie 3.1"[br]   elseif instr(info,"netcaptor 6.5.0rc1")>0 then[br]    browser="netcaptor 6.5.0rc1"[br]   elseif instr(info,"netcaptor 6.5.pb1")>0 then[br]    browser="netcaptor 6.5.pb1"[br]   elseif instr(info,"msie 5.5")>0 then[br]    browser="internet explorer 5.5"[br]   elseif instr(info,"msie 6.0")>0 then[br]    browser="internet explorer 6.0"[br]   elseif instr(info,"msie 6.0b")>0 then[br]    browser="internet explorer 6.0b"[br]   elseif instr(info,"msie 5.01")>0 then[br]    browser="internet explorer 5.01"[br]   elseif instr(info,"msie 5.0")>0 then[br]    browser="internet explorer 5.00"[br]   elseif instr(info,"msie 4.0")>0 then[br]    browser="internet explorer 4.01"[br]   else[br]    browser="其它"[br]   end if[br]end function[/p]
[p]    '****************************************************[br]'函数名:getsystem[br]'作 用:获取客户端操作系统[br]'返回值:客户端操作系统[br]'****************************************************[br]    function getsystem()[br]     info=request.servervariables(http_user_agent) [br]   if instr(info,"nt 5.1")>0 then[br]    system="windows xp"[br]   elseif instr(info,"tel")>0 then[br]    system="telport"[br]   elseif instr(info,"webzip")>0 then[br]    system="webzip"[br]   elseif instr(info,"flashget")>0 then[br]    system="flashget"[br]   elseif instr(info,"offline")>0 then[br]    system="offline"[br]   elseif instr(info,"nt 5")>0 then[br]    system="windows 2000"[br]   elseif instr(info,"nt 4")>0 then[br]    system="windows nt4"[br]   elseif instr(info,"98")>0 then[br]    system="windows 98"[br]   elseif instr(info,"95")>0 then[br]    system="windows 95"[br]   elseif instr(info,"unix") or instr(info,"linux") or instr(info,"sunos") or instr(info,"bsd") then[br]    system="类unix"[br]   elseif instr(thesoft,"mac") then[br]    system="mac"[br]   else[br]    system="其它"[br]   end if[br]end function[br][br]'****************************************************[br]'函数名:geturl[br]'作 用:获取url包括参数[br]'返回值:获取url包括参
该文章在 2010/7/3 14:15:14 编辑过