ASP 常用函数集合.docx

上传人:b****2 文档编号:3234841 上传时间:2023-05-05 格式:DOCX 页数:28 大小:22.93KB
下载 相关 举报
ASP 常用函数集合.docx_第1页
第1页 / 共28页
ASP 常用函数集合.docx_第2页
第2页 / 共28页
ASP 常用函数集合.docx_第3页
第3页 / 共28页
ASP 常用函数集合.docx_第4页
第4页 / 共28页
ASP 常用函数集合.docx_第5页
第5页 / 共28页
ASP 常用函数集合.docx_第6页
第6页 / 共28页
ASP 常用函数集合.docx_第7页
第7页 / 共28页
ASP 常用函数集合.docx_第8页
第8页 / 共28页
ASP 常用函数集合.docx_第9页
第9页 / 共28页
ASP 常用函数集合.docx_第10页
第10页 / 共28页
ASP 常用函数集合.docx_第11页
第11页 / 共28页
ASP 常用函数集合.docx_第12页
第12页 / 共28页
ASP 常用函数集合.docx_第13页
第13页 / 共28页
ASP 常用函数集合.docx_第14页
第14页 / 共28页
ASP 常用函数集合.docx_第15页
第15页 / 共28页
ASP 常用函数集合.docx_第16页
第16页 / 共28页
ASP 常用函数集合.docx_第17页
第17页 / 共28页
ASP 常用函数集合.docx_第18页
第18页 / 共28页
ASP 常用函数集合.docx_第19页
第19页 / 共28页
ASP 常用函数集合.docx_第20页
第20页 / 共28页
亲,该文档总共28页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

ASP 常用函数集合.docx

《ASP 常用函数集合.docx》由会员分享,可在线阅读,更多相关《ASP 常用函数集合.docx(28页珍藏版)》请在冰点文库上搜索。

ASP 常用函数集合.docx

ASP常用函数集合

<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%>

<%

StartTime=timer()'程序执行时间检测

'###############################################################

'┌──VIBO───────────────────┐

'│VIBOSTUDIO版权所有│

'└───────────────────────┘

'Author:

Vibo

'Email:

vibo_cn@

'-----------------ViboASP站点开发常用函数库------------------

'OpenDB(vdata_url)--------------------打开数据库

'getIp()-------------------------------得到真实IP

'getIPAdress(sip)------------------------查找ip对应的真实地址

'IP2Num(sip)----------------------------限制某段IP地址

'chkFrom()------------------------------防站外提交设定

'getsys()-------------------------------操作系统检测

'GetBrowser()---------------------------浏览器版本检测

'GetSearcher()--------------------------识别搜索引擎

'

'----------------------数据过滤↓----------------------------

'CheckStr(byValChkStr)-----------------检查无效字符

'CheckSql()-----------------------------防止SQL注入

'UnCheckStr(Str)-------------------------检查非法sql命令

'Checkstr(Str)--------------------------ASP最新SQL防注入过滤涵数

'HTMLEncode(reString)-------------------过滤转换HTML代码

'DateToStr(DateTime,ShowType)-----------日期转换函数

'Date2Chinese(iDate)--------------------获得ASP的中文日期字符串

'lenStr(str)----------------------------计算字符串长度(字节)

'CreateArr(str)-------------------------生成二维数组

'ShowRsArr(rsArr)-----------------------用表格显示记录集getrows生成的数组的表结构

'----------------------外接组件使用函数↓------------------------

'sendMail(to_Email,from_Email,from_Name,mail_Subject,mail_Body,mail_htmlBody)-----'Jmail组件发送邮件

'-----------------------------------------系统检测函数↓------------------------------------------

'IsValidUrl(url)------------------------检测网页是否有效

'getHTMLPage(filename)------------------获取文件内容

'CheckFile(FilePath)--------------------检查某一文件是否存在

'CheckDir(FolderPath)-------------------检查某一目录是否存在

'MakeNewsDir(foldername)----------------根据指定名称生成目录

'CreateHTMLPage(filename,FileData,C_mode)生成文件

'CheckBadWord(byValChkStr)-------------过滤脏字

'###############################################################

DimipData_url

ipData_url="./Ip.mdb"

Response.Write("--------------客户端信息检测------------"&"
")

Response.Write(getsys()&"
")

Response.Write(GetBrowser()&"
")

Response.Write(GetSearcher()&"
")

Response.Write("IP:

"&getIp()&"
")

Response.Write("来源:

"&(getIPAdress(GetIp()))&"
")

Response.Write("
")

Response.Write("--------------数据提交检测--------------"&"
")

ifnotchkFromthen

Response.write("请不要从站外提交内容!

"&"
")

Response.end

else

Response.write("本站提交内容!

"&"

")

Endif

functionOpenDB(vdata_url)

'------------------------------打开数据库

'使用:

Conn=OpenDB("data/data.mdb")

Dimvibo_Conn

Setvibo_Conn=Server.CreateObject("ADODB.Connection")

vibo_Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Server.MapPath(vdata_url)

vibo_Conn.Open

OpenDB=vibo_Conn

EndFunction

functiongetIp()

'-----------------------得到真实IP

userip=Request.ServerVariables("HTTP_X_FORWARDED_FOR")

Ifuserip=""Thenuserip=Request.ServerVariables("REMOTE_ADDR")

getIp=userip

Endfunction

FunctiongetIPAdress(sip)

'---------------------查找ip对应的真实地址

Dimiparr,iprs,country,city

Ifsip="127.0.0.1"thensip="192.168.0.1"

iparr=split(sip,".")

sip=cint(iparr(0))*256*256*256+cint(iparr

(1))*256*256+cint(iparr

(2))*256+cint(iparr(3))-1

Dimvibo_ipconn_STRING

vibo_ipconn_STRING="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Server.MapPath(ipData_url)

Setiprs=Server.CreateObject("ADODB.Recordset")

iprs.ActiveConnection=vibo_ipconn_STRING

iprs.Source="SELECTTop1city,countryFROMaddressWHEREip1<="&sip&"and"&sip&"<=ip2"

iprs.CursorType=0

iprs.CursorLocation=2

iprs.LockType=1

iprs.Open()

Ifiprs.bofandiprs.eofthen

country="未知地区"

city=""

Else

country=iprs.Fields.Item("country").Value

city=iprs.Fields.Item("city").Value

EndIf

getIPAdress=country&city

iprs.Close()

Setiprs=Nothing

EndFunction

FunctionIP2Num(sip)

'--------------------限制某段IP地址

dimstr1,str2,str3,str4

dimnum

IP2Num=0

ifisnumeric(left(sip,2))then

str1=left(sip,instr(sip,".")-1)

sip=mid(sip,instr(sip,".")+1)

str2=left(sip,instr(sip,".")-1)

sip=mid(sip,instr(sip,".")+1)

str3=left(sip,instr(sip,".")-1)

str4=mid(sip,instr(sip,".")+1)

num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1

IP2Num=num

endif

endfunction

'userIPnum=IP2Num(Request.ServerVariables("REMOTE_ADDR"))

'ifuserIPnum>IP2Num("192.168.0.0")anduserIPnum

'response.write("

您的IP被禁止
")

'response.end

'endif

FunctionchkFrom()

'----------------------------防站外提交设定

Dimserver_v1,server_v2,server1,server2

chkFrom=False

server1=Cstr(Request.ServerVariables("HTTP_REFERER"))

server2=Cstr(Request.ServerVariables("SERVER_NAME"))

IfMid(server1,8,len(server2))=server2ThenchkFrom=True

EndFunction

'ifnotchkFromthen

'Response.write("请不要从站外提交内容!

")

'Response.end

'Endif

functiongetsys()

'----------------------------------操作系统检测

vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")

ifinstr(vibo_soft,"WindowsNT5.0")then

msm="Win2000"

elseifinstr(vibo_soft,"WindowsNT5.1")then

msm="WinXP"

elseifinstr(vibo_soft,"WindowsNT5.2")then

msm="Win2003"

elseifinstr(vibo_soft,"4.0")then

msm="WinNT"

elseifinstr(vibo_soft,"NT")then

msm="WinNT"

elseifinstr(vibo_soft,"WindowsCE")then

msm="WindowsCE"

elseifinstr(vibo_soft,"Windows9")then

msm="Win9x"

elseifinstr(vibo_soft,"9x")then

msm="WindowsME"

elseifinstr(vibo_soft,"98")then

msm="Windows98"

elseifinstr(vibo_soft,"Windows95")then

msm="Windows95"

elseifinstr(vibo_soft,"Win32")then

msm="Win32"

elseifinstr(vibo_soft,"unix")orinstr(vibo_soft,"linux")orinstr(vibo_soft,"SunOS")orinstr(vibo_soft,"BSD")then

msm="类Unix"

elseifinstr(vibo_soft,"Mac")then

msm="Mac"

else

msm="Other"

endif

getsys=msm

EndFunction

functionGetBrowser()

'----------------------------------浏览器版本检测

dimvibo_soft

vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")

Browser="unknown"

version="unknown"

'vibo_soft="Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.0;TencentTraveler;.NETCLR1.1.4322)"

IfLeft(vibo_soft,7)="Mozilla"Then'有此标识为浏览器

vibo_soft=Split(vibo_soft,";")

IfInStr(vibo_soft

(1),"MSIE")>0Then

Browser="MicrosoftInternetExplorer"

version=Trim(Left(Replace(vibo_soft

(1),"MSIE",""),6))

ElseIfInStr(vibo_soft(4),"Netscape")>0Then

Browser="Netscape"

tmpstr=Split(vibo_soft(4),"/")

version=tmpstr(UBound(tmpstr))

ElseIfInStr(vibo_soft(4),"rv:

")>0Then

Browser="Mozilla"

tmpstr=Split(vibo_soft(4),":

")

version=tmpstr(UBound(tmpstr))

IfInStr(version,")")>0Then

tmpstr=Split(version,")")

version=tmpstr(0)

EndIf

EndIf

ElseIfLeft(vibo_soft,5)="Opera"Then

vibo_soft=Split(vibo_soft,"/")

Browser="Mozilla"

tmpstr=Split(vibo_soft

(1),"")

version=tmpstr(0)

EndIf

Ifversion<>"unknown"Then

DimTmpstr1

Tmpstr1=Trim(Replace(version,".",""))

IfNotIsNumeric(Tmpstr1)Then

version="unknown"

EndIf

EndIf

GetBrowser=Browser&""&version

Endfunction

functionGetSearcher()

'----------------------识别搜索引擎

Dimbotlist,Searcher

Dimvibo_soft

vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")

Botlist="Google,Isaac,SurveyBot,Baiduspider,ia_archiver,P.Arthur,FAST-WebCrawler,Java,Microsoft-ATL-Native,TurnitinBot,WebGather,Sleipnir,TencentTraveler"

Botlist=split(Botlist,",")

Fori=0toUBound(Botlist)

IfInStr(vibo_soft,Botlist(i))>0Then

Searcher=Botlist(i)&"搜索器"

IsSearch=True

ExitFor

EndIf

Next

IfIsSearchThen

GetSearcher=Searcher

else

GetSearcher="unknown"

Endif

Endfunction

'----------------------------------数据过滤↓---------------------------------------

FunctionCheckSql()'防止SQL注入

Dimsql_injdata

SQL_injdata="'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"

SQL_inj=split(SQL_Injdata,"|")

IfRequest.QueryString<>""Then

ForEachSQL_GetInRequest.QueryString

ForSQL_Data=0ToUbound(SQL_inj)

ifinstr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))>0Then

Response.Write"{alert('请不要在参数中包含非法字符!

');history.back(-1)}"

Response.end

endif

next

Next

EndIf

IfRequest.Form<>""Then

ForEachSql_PostInRequest.Form

ForSQL_Data=0ToUbound(SQL_inj)

ifinstr(Request.Form(Sql_Post),Sql_Inj(Sql_DATA))>0Then

Response.Write"{alert('请不要在参数中包含非法字符!

');history.back(-1)}"

Response.end

endif

next

next

endif

EndFunction

FunctionCheckStr(byValChkStr)'检查无效字符

DimStr:

Str=ChkStr

Str=Trim(Str)

IfIsNull(Str)Then

CheckStr=""

ExitFunction

EndIf

Dimre

Setre=newRegExp

re.IgnoreCase=True

re.Global=True

re.Pattern="(\r\n){3,}"

Str=re.Replace(Str,"$1$1$1")

Setre=Nothing

Str=Replace(Str,"'","''")

Str=Replace(Str,"select","select")

Str=Replace(Str,"join","join")

Str=Replace(Str,"union","union")

Str=Replace(Str,"where","where")

Str=Replace(Str,"insert","insert")

Str=Replace(Str,"delete","delete")

Str=Replace(Str,"update","update")

Str=Replace(Str,"like","like")

Str=Replace(Str,"drop","drop")

Str=Replace(Str,"create","create")

Str=Replace(Str,"modify","modify")

Str=Replace(Str,"rename","rename")

Str=Replace(Str,"alter","alter")

Str=Replace(Str,"cast","cast")

CheckStr=Str

EndFunction

FunctionUnCheckStr(Str)'检查非法sql命令

Str=Replace(Str,"select","select")

Str=Replace(Str,"join","join")

Str=Replace(Str,"union","union")

Str=Replace(Str,"where","where")

Str=Replace(Str,"insert","insert")

Str=Replace(Str,"delete","delete")

Str=Replace(Str,"update","update")

Str=Replace(Str,"like","like")

Str=Replace(Str,"drop","drop")

Str=Repl

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2