LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

常用ASP函数封装

admin
2010年7月3日 14:15 本文热度 5846

<%
'-------------------------------------
'天枫asp class v1.0,集常用asp函数于一体
'天枫版权所有http://52515.net
'qq:76994859 email:chenshaobo@gmail.com

'所有功能函数名如下:
' strlength(str) 取得字符串长度
' cutstr(str,strlen) 字符串长度切割
' checkisempty(tstr) 检测是否为空
' isinteger(para) 整数检验
' checkname(str) 名字字符校验
' checkpassword(str) 密码检验
' checkemail(email) 邮箱格式检验
' alert(msg,gourl) 弹出对话框提示
' goback(str1,str2,isback) 出错信息提示
' suc(str1,str2,url) 操作成功信息提示
' chkpost() 检测是否站外提交表单
' psql() 防止sql注入
' filtratehtmlcode(str) 防止生成html
' htmlcode(str) 过滤html
' replacehtml(tstr) 清滤html
' getip() 获取客户端ip
' getbrowser 获取客户端浏览器信
' getsystem 获取客户端操作系统
' geturl() 获取当前页面url包含参数
' curl() 获取当前页面url
' getextend 取得文件扩展名
' checkexist(table,fieldname,fieldcontent,isblur) 检测某个表中某个字段的内容是否存在
' getnum(table,fieldname,resulttype,args) 检测某个表某个字段有多少条,最大值 ,最小值等
' getfoldersize(folderpath) 计算某个文件夹的大小
' getfilesize(filename) 计算某个文件的大小
' isobjinstalled(strclassstring) 检测组件是否安装
' sendmail jmail发送邮件
' responsecookies 写入cookies
' cleancookies 清除cookies
' gettimeover 取得程序页面执行时间
' formatsize 大小格式化
' formattime 时间格式化
' zodiac 取得生肖
' constellation 取得星座
'-------------------------------------

class cls_fun

'--------字符处理--------------------------

'****************************************************
'函数名:strlength
'作 用:取得字符串长度(汉字为2)
'参 数:str ----字符串内容
'返回值:字符串长度
'****************************************************
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

'****************************************************
'函数名:cutstr
'作 用:字符串长度切割,超过显示省略号
'参 数:str ----字符串内容
' strlen ------要显示的长度
'返回值:切割后字符串内容
'****************************************************
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

'--------------系列验证----------------------------

'****************************************************
'函数名:checkisempty
'作 用:检查是否为空
'参 数: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

'****************************************************
'函数名:isinteger
'作 用:整数检验
'参 数:tstr ----字符
'返回值:true是整数,false不是整数
'****************************************************
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

'****************************************************
'函数名:checkname
'作 用:名字字符检验
'参 数:str ----字符串
'返回值:true无误,false有误
'****************************************************
public function checkname(str)
checkname=true
dim rep,pass
set rep=new regexp
rep.global=true
rep.ignorecase=true
'匹配字母、数字、下划线、汉字且必须以字母或下划线或汉字开始
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

'****************************************************
'函数名:checkpassword
'作 用:密码检验
'参 数: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
'匹配字母、数字、下划线、点号
rep.pattern="[a-za-z0-9_\.]+$"
pass=rep.test(str)
set rep=nothing
if not pass then checkpassword=false
end if
end function

'****************************************************
'函数名:checkemail
'作 用:邮箱格式检测
'参 数: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

'--------------信息提示----------------------------
'****************************************************
'函数名:alert
'作 用:弹出对话框提示
'参 数:msg ----对话框信息
' gourl ----提示后转向哪里
'返回值:无
'****************************************************
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

'****************************************************
'函数名:goback
'作 用:错误信息提示
'参 数:str1 ----信息提示标题
' str2 ----信息提示内容
' isback ----是否显示返回
'返回值:无
'****************************************************
public function goback(str1,str2,isback)
if str1="" then str1="错误信息"
if str2="" then str2="请填写完整必填项目"
if isback="" then
str2=str2&" 返回重填"
else
str2=str2
end if
response.write"

"&str1&"
×
"&str2&"
"
response.end
end function

'****************************************************
'函数名:suc
'作 用:成功提示信息
'参 数:str1 ----信息提示标题
' str2 ----信息提示内容
' 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&"  返回继续管理"
response.write"

"&str1&"
"&str2&"
"
end function

'--------------安全处理----------------------------

'****************************************************
'函数名:chkpost
'作 用:禁止站外提交表单
'返回值:true站内提交,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

'****************************************************
'函数名:psql
'作 用:防止sql注入
'返回值:为空则无注入,不为空则注入并返回注入的字符
'****************************************************
public function psql()
psql=""
badwords= "'防''防;防and防exec防insert防select防update防delete防count防*防%防chr防mid防master防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

'****************************************************
'函数名:filtratehtmlcode
'作 用:防止生成html代码
'参 数: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

'函数名:htmlcode
'作 用:过滤html标签
'参 数: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

'****************************************************
'函数名:replacehtml
'作 用:清理html
'参 数: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

'---------------获取客户端和服务端的一些信息-------------------

'****************************************************
'函数名: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

'****************************************************
'函数名: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

'****************************************************
'函数名:getsystem
'作 用:获取客户端操作系统
'返回值:客户端操作系统
'****************************************************
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

'****************************************************
'函数名:geturl
'作 用:获取url包括参数
'返回值:获取url包括参


该文章在 2010/7/3 14:15:14 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved