一些小asp的函数
'*************************************
'获取客户端IP
'*************************************
function getIP()
dim strIP,IP_Ary,strIP_list
strIP_list=Replace(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),"'","")
If InStr(strIP_list,",")<>0 Then
IP_Ary = Split(strIP_list,",")
strIP = IP_Ary(0)
Else
strIP = strIP_list
End IF
If strIP=Empty Then strIP=Replace(Request.ServerVariables("REMOTE_ADDR"),"'","")
getIP=strIP
End Function
'转换IP函数
'转换IP函数
function splitip(ip)
dim yl_ip
yl_ip=split(IP,".")
splitip=""&yl_ip(0)&"."&yl_ip(1)&"."&yl_ip(2)&".★"
end function
'*************************************
'获取客户端浏览器信息
'*************************************
function getBrowser(strUA)
dim arrInfo,strType,temp1,temp2
strType=""
strUA=LCase(strUA)
arrInfo=Array("Unkown","Unkown")
'浏览器判断
if Instr(strUA,"mozilla")>0 then arrInfo(0)="Mozilla"
if Instr(strUA,"icab")>0 then arrInfo(0)="iCab"
if Instr(strUA,"lynx")>0 then arrInfo(0)="Lynx"
if Instr(strUA,"links")>0 then arrInfo(0)="Links"
if Instr(strUA,"elinks")>0 then arrInfo(0)="ELinks"
if Instr(strUA,"jbrowser")>0 then arrInfo(0)="JBrowser"
if Instr(strUA,"konqueror")>0 then arrInfo(0)="konqueror"
if Instr(strUA,"wget")>0 then arrInfo(0)="wget"
if Instr(strUA,"ask jeeves")>0 or Instr(strUA,"teoma")>0 then arrInfo(0)="Ask Jeeves/Teoma"
if Instr(strUA,"wget")>0 then arrInfo(0)="wget"
if Instr(strUA,"opera")>0 then arrInfo(0)="opera"
if Instr(strUA,"gecko")>0 then
strType="[Gecko]"
arrInfo(0)="Mozilla"
if Instr(strUA,"aol")>0 then arrInfo(0)="AOL"
if Instr(strUA,"netscape")>0 then arrInfo(0)="Netscape"
if Instr(strUA,"firefox")>0 then arrInfo(0)="FireFox"
if Instr(strUA,"chimera")>0 then arrInfo(0)="Chimera"
if Instr(strUA,"camino")>0 then arrInfo(0)="Camino"
if Instr(strUA,"galeon")>0 then arrInfo(0)="Galeon"
if Instr(strUA,"k-meleon")>0 then arrInfo(0)="K-Meleon"
arrInfo(0)=arrInfo(0)+strType
end if
if Instr(strUA,"bot")>0 or Instr(strUA,"crawl")>0 then
strType="[Bot/Crawler]"
arrInfo(0)=""
if Instr(strUA,"grub")>0 then arrInfo(0)="Grub"
if Instr(strUA,"googlebot")>0 then arrInfo(0)="GoogleBot"
if Instr(strUA,"msnbot")>0 then arrInfo(0)="MSN Bot"
if Instr(strUA,"slurp")>0 then arrInfo(0)="Yahoo! Slurp"
arrInfo(0)=arrInfo(0)+strType
end if
if Instr(strUA,"applewebkit")>0 then
strType="[AppleWebKit]"
arrInfo(0)=""
if Instr(strUA,"omniweb")>0 then arrInfo(0)="OmniWeb"
if Instr(strUA,"safari")>0 then arrInfo(0)="Safari"
arrInfo(0)=arrInfo(0)+strType
end if
if Instr(strUA,"msie")>0 then
strType="[MSIE"
temp1=mid(strUA,(Instr(strUA,"msie")+4),6)
temp2=Instr(temp1,";")
temp1=left(temp1,temp2-1)
strType=strType & temp1 &"]"
arrInfo(0)="Internet Explorer"
if Instr(strUA,"msn")>0 then arrInfo(0)="MSN"
if Instr(strUA,"aol")>0 then arrInfo(0)="AOL"
if Instr(strUA,"webtv")>0 then arrInfo(0)="WebTV"
if Instr(strUA,"myie2")>0 then arrInfo(0)="MyIE2"
if Instr(strUA,"maxthon")>0 then arrInfo(0)="Maxthon"
if Instr(strUA,"gosurf")>0 then arrInfo(0)="GoSurf"
if Instr(strUA,"netcaptor")>0 then arrInfo(0)="NetCaptor"
if Instr(strUA,"sleipnir")>0 then arrInfo(0)="Sleipnir"
if Instr(strUA,"avant browser")>0 then arrInfo(0)="AvantBrowser"
if Instr(strUA,"greenbrowser")>0 then arrInfo(0)="GreenBrowser"
if Instr(strUA,"slimbrowser")>0 then arrInfo(0)="SlimBrowser"
arrInfo(0)=arrInfo(0)+strType
end if
'操作系统判断
if Instr(strUA,"windows")>0 then arrInfo(1)="Windows"
if Instr(strUA,"windows ce")>0 then arrInfo(1)="Windows CE"
if Instr(strUA,"windows 95")>0 then arrInfo(1)="Windows 95"
if Instr(strUA,"win98")>0 then arrInfo(1)="Windows 98"
if Instr(strUA,"windows 98")>0 then arrInfo(1)="Windows 98"
if Instr(strUA,"windows 2000")>0 then arrInfo(1)="Windows 2000"
if Instr(strUA,"windows xp")>0 then arrInfo(1)="Windows XP"
if Instr(strUA,"windows nt")>0 then
arrInfo(1)="Windows NT"
if Instr(strUA,"windows nt 5.0")>0 then arrInfo(1)="Windows 2000"
if Instr(strUA,"windows nt 5.1")>0 then arrInfo(1)="Windows XP"
if Instr(strUA,"windows nt 5.2")>0 then arrInfo(1)="Windows 2003"
end if
if Instr(strUA,"x11")>0 or Instr(strUA,"unix")>0 then arrInfo(1)="Unix"
if Instr(strUA,"sunos")>0 or Instr(strUA,"sun os")>0 then arrInfo(1)="SUN OS"
if Instr(strUA,"powerpc")>0 or Instr(strUA,"ppc")>0 then arrInfo(1)="PowerPC"
if Instr(strUA,"macintosh")>0 then arrInfo(1)="Mac"
if Instr(strUA,"mac osx")>0 then arrInfo(1)="MacOSX"
if Instr(strUA,"freebsd")>0 then arrInfo(1)="FreeBSD"
if Instr(strUA,"linux")>0 then arrInfo(1)="Linux"
if Instr(strUA,"palmsource")>0 or Instr(strUA,"palmos")>0 then arrInfo(1)="PalmOS"
if Instr(strUA,"wap ")>0 then arrInfo(1)="WAP"
'arrInfo(0)=strUA
getBrowser=arrInfo
end function
'*************************************
'检测系统组件是否安装
'*************************************
Function CheckObjInstalled(strClassString)
On Error Resume Next
Dim Temp
Err = 0
Dim TmpObj
Set TmpObj = Server.CreateObject(strClassString)
Temp = Err
IF Temp = 0 OR Temp = -2147221477 Then
CheckObjInstalled=true
ElseIF Temp = 1 OR Temp = -2147221005 Then
CheckObjInstalled=false
End IF
Err.Clear
Set TmpObj = Nothing
Err = 0
End Function
'*************************************
'判断服务器Microsoft.XMLDOM
'*************************************
Function getXMLDOM
On Error Resume Next
Dim Temp
getXMLDOM="Microsoft.XMLDOM"
Err = 0
Dim TmpObj
Set TmpObj = Server.CreateObject(getXMLDOM)
Temp = Err
IF Temp = 1 OR Temp = -2147221005 Then
getXMLDOM="Msxml2.DOMDocument.5.0"
End IF
Err.Clear
Set TmpObj = Nothing
Err = 0
end function
'*************************************
'判断服务器MSXML2.ServerXMLHTTP
'*************************************
Function getXMLHTTP
On Error Resume Next
Dim Temp
getXMLHTTP="MSXML2.ServerXMLHTTP"
Err = 0
Dim TmpObj
Set TmpObj = Server.CreateObject(getXMLHTTP)
Temp = Err
IF Temp = 1 OR Temp = -2147221005 Then
getXMLHTTP="Msxml2.ServerXMLHTTP.5.0"
End IF
Err.Clear
Set TmpObj = Nothing
Err = 0
end function
'*************************************
'检查插件是否成功安装
'*************************************
Function Checkplugins
Dim PlugS,Plug,PlugItem
Checkplugins=-1
PlugS=Split(function_Plugin,"$*$")
For Each Plug In PlugS
PlugItem = Split(Plug,"%|%")
If Getplugins=PlugItem(0) Then
Checkplugins=PlugItem
Exit Function
End If
Next
End Function
'//验证码控制
sub codestt(codestr)
If codestr="" Then
tourlRedirect("请返回输入确认码。返回后请刷新登录页面后重新输入正确的信息。")
response.End()
Exit Sub
Elseif Session("getcode")="9999" then
Session("getcode")=""
Elseif Session("getcode")="" then
tourlRedirect("请不要重复提交,如需重新登录请返回登录页面。")
response.End()
Exit Sub
ElseIf Cstr(Session("GetCode"))<>Cstr(trim(codestr)) Then
tourlRedirect("您输入的确认码和系统产生的不一致,请重新输入。返回后请刷新登录页面后重新输入正确的信息!")
response.End()
Exit Sub
End If
Session("getcode")=""
end sub
'转换时间函数//年月日
function yl_addnow(addnow)
'dim yl_yearr,yl_mmm,yl_ddd,yl_hhh,yl_nnn,yl_sss
'yl_yearr=datepart("yyyy",addnow)
'yl_mmm=datepart("m",addnow)
'yl_ddd=datepart("d",addnow)
'yl_hhh=datepart("h",addnow)
'yl_nnn=datepart("n",addnow)
'yl_sss=datepart("s",addnow)
'yl_addnow=""&yl_yearr&"年"&yl_mmm&"月"&yl_ddd&"日 "&yl_hhh&"时"&yl_nnn&"分"&yl_sss&"秒"
dim yl_year,yl_month,yl_day,yl_hour,yl_minute,yl_ss
yl_year=year(addnow)
if len(yl_year)=2 then yl_year="20"&yl_year
yl_month=month(addnow)
if yl_month<10 then yl_month="0"&yl_month
yl_day=day(addnow)
if yl_day<10 then yl_day="0"&yl_day
yl_hour=hour(addnow)
if yl_hour<10 then yl_hour="0"&yl_hour
yl_minute=minute(addnow)
if yl_minute<10 then yl_minute="0"&yl_minute
yl_ss=second(addnow)
if yl_ss<10 then yl_ss="0"&yl_ss
yl_addnow=""&yl_year&"年"&yl_month&"月"&yl_day&"日 "&yl_hour&"时"&yl_minute&"分"&yl_ss&"秒"
end function
'转换日期时间函数
function yl_now(nowtime)
'yl_now = year(nowtime)&month(nowtime)&day(nowtime)&hour(nowtime)&minute(nowtime)&second(nowtime)
dim yl_year,yl_month,yl_day,yl_hour,yl_minute,yl_ss
yl_year=year(nowtime)
if len(yl_year)=2 then yl_year="20"&yl_year
yl_month=month(nowtime)
if yl_month<10 then yl_month="0"&yl_month
yl_day=day(nowtime)
if yl_day<10 then yl_day="0"&yl_day
yl_hour=hour(nowtime)
if yl_hour<10 then yl_hour="0"&yl_hour
yl_minute=minute(nowtime)
if yl_minute<10 then yl_minute="0"&yl_minute
yl_ss=second(nowtime)
if yl_ss<10 then yl_ss="0"&yl_ss
yl_now=""&yl_year&""&yl_month&""&yl_day&""&yl_hour&""&yl_minute&""&yl_ss&""
end function
'转换日期函数
function yl_date(nowdate)
'yl_date=""&year(nowdate)&"-"&month(nowdate)&"-"&day(nowdate)&""
dim yl_year,yl_month,yl_day,yl_hour,yl_minute,yl_ss
yl_year=year(nowdate)
if len(yl_year)=2 then yl_year="20"&yl_year
yl_month=month(nowdate)
if yl_month<10 then yl_month="0"&yl_month
yl_day=day(nowdate)
if yl_day<10 then yl_day="0"&yl_day
yl_date = ""&yl_year&"-"&yl_month&"-"&yl_day&""
end function
'*************************************
'日期转换函数
'*************************************
Function DateToStr(DateTime,ShowType)
Dim DateMonth,DateDay,DateHour,DateMinute,DateWeek,DateSecond
Dim FullWeekday,shortWeekday,Fullmonth,Shortmonth,TimeZone1,TimeZone2
TimeZone1="+0800"
TimeZone2="+08:00"
FullWeekday=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
shortWeekday=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
Fullmonth=Array("January","February","March","April","May","June","July","August","September","October","November","December")
Shortmonth=Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
DateMonth=Month(DateTime)
DateDay=Day(DateTime)
DateHour=Hour(DateTime)
DateMinute=Minute(DateTime)
DateWeek=weekday(DateTime)
DateSecond=Second(DateTime)
If Len(DateMonth)<2 Then DateMonth="0"&DateMonth
If Len(DateDay)<2 Then DateDay="0"&DateDay
If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
Select Case ShowType
Case "Y-m-d"
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay
Case "Y-m-d H:I A"
Dim DateAMPM
If DateHour>12 Then
DateHour=DateHour-12
DateAMPM="PM"
Else
DateHour=DateHour
DateAMPM="AM"
End If
If Len(DateHour)<2 Then DateHour="0"&DateHour
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&" "&DateAMPM
Case "Y-m-d H:I:S"
If Len(DateHour)<2 Then DateHour="0"&DateHour
If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&":"&DateSecond
Case "YmdHIS"
DateSecond=Second(DateTime)
If Len(DateHour)<2 Then DateHour="0"&DateHour
If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
DateToStr=Year(DateTime)&DateMonth&DateDay&DateHour&DateMinute&DateSecond
Case "ym"
DateToStr=Right(Year(DateTime),2)&DateMonth
Case "d"
DateToStr=DateDay
Case "ymd"
DateToStr=Right(Year(DateTime),4)&DateMonth&DateDay
Case "mdy"
Dim DayEnd
select Case DateDay
Case 1
DayEnd="st"
Case 2
DayEnd="nd"
Case 3
DayEnd="rd"
Case Else
DayEnd="th"
End Select
DateToStr=Fullmonth(DateMonth-1)&" "&DateDay&DayEnd&" "&Right(Year(DateTime),4)
Case "w,d m y H:I:S"
DateSecond=Second(DateTime)
If Len(DateHour)<2 Then DateHour="0"&DateHour
If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
DateToStr=shortWeekday(DateWeek-1)&","&DateDay&" "& Left(Fullmonth(DateMonth-1),3) &" "&Right(Year(DateTime),4)&" "&DateHour&":"&DateMinute&":"&DateSecond&" "&TimeZone1
Case "y-m-dTH:I:S"
If Len(DateHour)<2 Then DateHour="0"&DateHour
If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&"T"&DateHour&":"&DateMinute&":"&DateSecond&TimeZone2
Case Else
If Len(DateHour)<2 Then DateHour="0"&DateHour
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute
End Select
End Function
'*************************************
'计算随机数
'*************************************
function randomStr(intLength)
dim strSeed,seedLength,pos,str,i
strSeed = "abcdefghijklmnopqrstuvwxyz1234567890"
seedLength=len(strSeed)
str=""
Randomize
for i=1 to intLength
str=str+mid(strSeed,int(seedLength*rnd)+1,1)
next
randomStr=str
end function
'生成随机字符串开始
Function Createpass(LengthNum)
Dim Ran,i
if Not IsNumeric(LengthNum) then LengthNum=16
Createpass=""
For i=1 To LengthNum
Randomize
Ran = CInt(Rnd * 2)
Randomize
If Ran = 0 Then
Ran = CInt(Rnd * 25) + 97
Createpass =Createpass& UCase(Chr(Ran))
ElseIf Ran = 1 Then
Ran = CInt(Rnd * 9)
Createpass = Createpass & Ran
ElseIf Ran = 2 Then
Ran = CInt(Rnd * 25) + 97
Createpass =Createpass& Chr(Ran)
End If
Next
End Function
'调用...
'ranNum=Createpass(15)
'randomize
'ranNum=int(90000*rnd)+10000
'生成随机字符串结束
'模版替换函数开始
Function TempletContent(TempletContents)
TempletContent=replace(TempletContents,"$homepage_url$",homepage_url) '网站域名替换模版
TempletContent=replace(TempletContent,"$homepage_link$",homepage_link) '网站首页替换模版
TempletContent=replace(TempletContent,"$news_location$",news_location) '网站目录替换模版
TempletContent=replace(TempletContent,"$metas$",metas) 'meta替换模版
TempletContent=replace(TempletContent,"$info_table$",info_table) '网页宽度替换模版
TempletContent=replace(TempletContent,"$t_images$",t_images) '栏目分类图标替换模版
TempletContent=replace(TempletContent,"$ntype$",ntype) '栏目分类替换模版
TempletContent=replace(TempletContent,"$yl_infoclass$",ntypeid) '栏目分类ID替换模版
TempletContent=replace(TempletContent,"$typeurl$",typeurl) '栏目分类地址替换模版
TempletContent=replace(TempletContent,"$yl_title$",yl_title) '标题替换模版
TempletContent=replace(TempletContent,"$adddate$",adddate) '时间替换模版
'TempletContent=replace(TempletContent,"$testcodes$",testcodes) '内容替换模版
TempletContent=replace(TempletContent,"$yl_name$",yl_name) '作者替换模版
TempletContent=replace(TempletContent,"$yl_xxly$",yl_xxly) '来源替换模版
End Function
'模版替换函数结束
'====================================生成HTML开始
'定义xmlhttp
function GetXmlText(Url)
dim GetXmlHttp
set GetXmlHttp=server.Createobject("Microsoft.XMLHTTP")
GetXmlHttp.open "Get",url,false,"",""
GetXmlHttp.Send
'GetXmlText=GetXmlHttp.Responsetext
GetXmlText=GetXmlHttp.ResponseBody
set GetXmlHttp=nothing
end function
|
'转换为字符
Function BytesToBstr(body,Cset) dim objstream set objstream = Server.CreateObject("adodb.stream") objstream.Type = 1 objstream.Mode =3 objstream.Open objstream.Write body objstream.Position = 0 objstream.Type = 2 objstream.Charset = Cset BytesToBstr = objstream.ReadText objstream.Close set objstream = nothing End Function '保存文件 Sub SaveToFile(strBody,File) Dim objStream Set objStream = Server.CreateObject("ADODB.Stream") With objStream .Type = 2 .Open .Charset = "GB2312" .Position = objStream.Size .WriteText = strBody .SaveToFile Server.MapPath(File),2 .Close End With Set objStream = Nothing End Sub '创建文件 Sub FSOSaveFile(Content,LocalFileName) Dim FileObj,FilePionter 'response.write LocalFileName 'response.end Set FileObj=Server.CreateObject(G_FS_FSO) Set FilePionter = FileObj.CreateTextFile(Server.MapPath(LocalFileName),True) FilePionter.Write Replace(Content,Webdomain,"") FilePionter.close '释放对象 Set FilePionter = Nothing Set FileObj = Nothing End Sub '====================================生成HTML结束 '截取信息开始 'strs=rsinfoall("yl_body") 'bodys=stripHTML(strs) 'bodys=cutStr(bodys,350) Function stripHTML(strHTML) Dim objRegExp, strOutput Set objRegExp = New Regexp objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = "<(.[^>]*)>" strOutput = objRegExp.Replace(strHTML, "") strOutput = Replace(strOutput, "<", "<") strOutput = Replace(strOutput, ">", ">") stripHTML = strOutput Set objRegExp = Nothing End Function function cutStr(strs,strlen) dim l,t,c,i l=len(strs) t=0 for i=1 to l c=Abs(Asc(Mid(strs,i,1))) if c>255 then t=t+2 else t=t+1 end if if t>=strlen then cutStr=left(strs,i)&"..." exit for else cutStr=strs end if next cutStr=replace(cutStr,chr(10),"") cutStr=Replace(cutStr,chr(13),"") end function '截取信息结束 '************************************* '切割内容 - 按行分割 '************************************* Function SplitLines(byVal Content,byVal ContentNums) Dim ts,i,l ContentNums=int(ContentNums) If IsNull(Content) Then Exit Function i=1 ts = 0 For i=1 to Len(Content) l=Lcase(Mid(Content,i,5)) If l="<br/>" Then ts=ts+1 End If l=Lcase(Mid(Content,i,4)) If l="<br>" Then ts=ts+1 End If l=Lcase(Mid(Content,i,3)) If l="<p>" Then ts=ts+1 End If If ts>ContentNums Then Exit For Next If ts>ContentNums Then Content=Left(Content,i-1) End If SplitLines=Content End Function '************************************* '************************************* '************************************* '//水印
'过滤跨站脚本和HTML标签 |

浙公网安备 33010602011771号