高手推荐的有用的ASP函数集合(1)

网络整理 - 08-30

现在不写asp了,这次我将我以前沉淀下的一些函数库共享给大家,希望能给初学者启示,给老手也有所帮助吧,先谢谢大家支持!

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
StartTime=timer() '程序执行时间检测

'###############################################################
'┌──VIBO───────────────────┐
'│             VIBO STUDIO 版权所有             │
'└───────────────────────┘
' Author:Vibo
' Email:vibo_cn@hotmail.com
'----------------- Vibo ASP站点开发常用函数库 ------------------
'OpenDB(vdata_url)   -------------------- 打开数据库
'getIp()  ------------------------------- 得到真实IP
'getIPAdress(sip)------------------------ 查找ip对应的真实地址
'IP2Num(sip) ---------------------------- 限制某段IP地址
'chkFrom() ------------------------------ 防站外提交设定
'getsys() ------------------------------- 操作系统检测
'GetBrowser() --------------------------- 浏览器版本检测
'GetSearcher() -------------------------- 识别搜索引擎
'
'---------------------- 数据过滤 ↓----------------------------
'CheckStr(byVal ChkStr) ----------------- 检查无效字符
'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(byVal ChkStr) ------------- 过滤脏字
'###############################################################

Dim ipData_url
ipData_url="./Ip.mdb"

Response.Write("--------------客户端信息检测------------"&"<br>")
Response.Write(getsys()&"<br>")
Response.Write(GetBrowser()&"<br>")
Response.Write(GetSearcher()&"<br>")
Response.Write("IP:"&getIp()&"<br>")
Response.Write("来源:"&(getIPAdress(GetIp()))&"<br>")
Response.Write("<br>")

Response.Write("--------------数据提交检测--------------"&"<br>")
if not chkFrom then
    Response.write("请不要从站外提交内容!"&"<br>")
    Response.end
else
    Response.write("本站提交内容!"&"<br><br>")
End if
function OpenDB(vdata_url)
'------------------------------打开数据库
'使用:Conn = OpenDB("data/data.mdb")
  Dim vibo_Conn
  Set vibo_Conn= Server.CreateObject("ADODB.Connection")
  vibo_Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(vdata_url)
  vibo_Conn.Open
  OpenDB=vibo_Conn
End Function

function getIp()
'-----------------------得到真实IP
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then userip = Request.ServerVariables("REMOTE_ADDR")
getIp=userip
End function

Function getIPAdress(sip)
'---------------------查找ip对应的真实地址
Dim iparr,iprs,country,city
If sip="127.0.0.1" then sip= "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
Dim vibo_ipconn_STRING
vibo_ipconn_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(ipData_url)
Set iprs = Server.CreateObject("ADODB.Recordset")
iprs.ActiveConnection = vibo_ipconn_STRING
iprs.Source = "SELECT Top 1 city, country FROM address WHERE ip1 <=" & sip & " and " & sip & "<=ip2"
iprs.CursorType = 0
iprs.CursorLocation = 2
iprs.LockType = 1
iprs.Open()

If iprs.bof and iprs.eof then
    country="未知地区"
    city=""
Else
    country=iprs.Fields.Item("country").Value
    city=iprs.Fields.Item("city").Value
End If
getIPAdress=country&city
iprs.Close()
Set iprs = Nothing
End Function

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

    dim str1,str2,str3,str4
    dim num
    IP2Num=0
    if isnumeric(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
    end if
end function

'userIPnum = IP2Num(Request.ServerVariables("REMOTE_ADDR"))
'if userIPnum > IP2Num("192.168.0.0") and userIPnum < IP2Num("192.168.0.255") then
    'response.write ("<center>您的IP被禁止</center>")
    'response.end
'end if
Function chkFrom()
'----------------------------防站外提交设定
    Dim server_v1,server_v2, server1, server2
    chkFrom=False
    server1=Cstr(Request.ServerVariables("HTTP_REFERER"))
    server2=Cstr(Request.ServerVariables("SERVER_NAME"))
    If Mid(server1,8,len(server2))=server2 Then chkFrom=True
End Function
'if not chkFrom then
    'Response.write("请不要从站外提交内容!")
    'Response.end
'End if

function getsys()
'----------------------------------操作系统检测
vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")
if instr(vibo_soft,"Windows NT 5.0") then
    msm="Win 2000"
elseif instr(vibo_soft,"Windows NT 5.1") then
    msm="Win XP"
elseif instr(vibo_soft,"Windows NT 5.2") then
    msm="Win 2003"
elseif instr(vibo_soft,"4.0") then
    msm="Win NT"
elseif instr(vibo_soft,"NT") then
    msm="Win NT"
elseif instr(vibo_soft,"Windows CE") then
    msm="Windows CE"
elseif instr(vibo_soft,"Windows 9") then
    msm="Win 9x"
elseif instr(vibo_soft,"9x") then
    msm="Windows ME"
elseif instr(vibo_soft,"98") then
    msm="Windows 98"
elseif instr(vibo_soft,"Windows 95") then
    msm="Windows 95"
elseif instr(vibo_soft,"Win32") then
    msm="Win32"
elseif instr(vibo_soft,"unix") or instr(vibo_soft,"linux") or instr(vibo_soft,"SunOS") or instr(vibo_soft,"BSD") then
    msm="类Unix"
elseif instr(vibo_soft,"Mac") then
    msm="Mac"
else
    msm="Other"
end if
getsys=msm
End Function