木工雕刻全书在线阅读:在ASP页面中取得来访者的操作系统和IE版本的代码分别是什么?

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 03:13:07
在ASP页面中取得来访者的操作系统和IE浏览器版本的代码分别是什么?
请分开来分行写
请将代码详细地写出来
前三种的显示效果都是:
4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)
不好,还不行

<p align=center>获取客户端浏览器和操作系统信息的方法</p>
<Script language=Vbscript>
''用VBS中的Navigator.appVersion(或者.UserAgent)属性=
''=此种方法可以在客户端显示,但是不可以保存到服务器端数据库里=
Document.write Navigator.appVersion&"<p>"
Function Browser(Info)
Info=Navigator.appVersion ''在这里初始化了Info,在实际应用中可以作为其他变量赋值
If InStr(Info,"MSIE 6")>0 Then
Browser="Internet Explorer 6.0"
ElseIf InStr(Info,"MSIE 5.5")>0 Then
Browser="Internet Explorer 5.5"
ElseIf InStr(Info,"MSIE 5.0")>0 Then
Browser="Internet Explorer 5.0"
ElseIf InStr(Info,"MSIE 4")>0 Then
Browser="Internet Explorer 4.0"
Else
Browser="未知的浏览器!"
End if
Document.Write "您的浏览器是:"&Browser&"<p>"
End Function
Function System(Info)
Info=Navigator.appVersion
If InStr(Info,"NT 5.1")>0 Then
System="Windows XP"
ElseIf InStr(Info,"NT 5.0")>0 Then
System="Windows 2000"
ElseIf InStr(Info,"NT 4")>0 Then
System="Windows NT"
ElseIf InStr(Info,"98")>0 Then
System="Windows 98"
ElseIf InStr(Info,"Me")>0 Then
System="Windows Me"
ElseIf InStr(Info,"95")>0 Then
System="Windows 95"
Else
System="未知的操作系统!"
End if
Document.Write "您的操作系统是:"&System&"<p>"
End Function
Call Browser(Info)
Call System(Info)
</Script>

response.Write operationsystem & "<br>" & browser
function operationsystem() '操作系统版本
agent = Request.ServerVariables("HTTP_USER_AGENT")
if Instr(agent,"NT 5.2")>0 then
SystemVer="Windows Server 2003"
elseif Instr(agent,"NT 5.1")>0 then
SystemVer="Windows XP"
elseif Instr(agent,"NT 5")>0 then
SystemVer="Windows 2000"
elseif Instr(agent,"NT 4")>0 then
SystemVer="Windows NT4"
elseif Instr(agent,"4.9")>0 then
SystemVer="Windows ME"
elseif Instr(agent,"98")>0 then
SystemVer="Windows 98"
elseif Instr(agent,"95")>0 then
SystemVer="Windows 95"

else
SystemVer="未知"
end if
operationsystem="操作系统: " & SystemVer
end function

function browser() '浏览器版本
agent = Request.ServerVariables("HTTP_USER_AGENT")
if Instr(agent,"MSIE 6.0")>0 then
browserVer="Internet Explorer 6.0"
elseif Instr(agent,"MSIE 5.5")>0 then
browserVer="Internet Explorer 5.5"
elseif Instr(agent,"MSIE 5.01")>0 then
browserVer="Internet Explorer 5.01"
elseif Instr(agent,"MSIE 5.0")>0 then
browserVer="Internet Explorer 5.00"
elseif Instr(agent,"MSIE 4.0")>0 then
browserVer="Internet Explorer 4.0"
else
browserVer="未知"
end if
browser="浏览器: " & browserVer
if Instr(agent,"TencentTraveler")>0 then '检查是否正在使用腾讯TT
browser=browser&" |目前正使用TencentTraveler"
end if
end function

Request对象

ASP如何获取客户端操作系统版本

自定义函数:
function operationsystem() '操作系统版本
agent = Request.ServerVariables("HTTP_USER_AGENT")
if Instr(agent,"NT 5.1")>0 then
SystemVer="Windows XP"
elseif Instr(agent,"NT 5")>0 then
SystemVer="Windows 2000"
elseif Instr(agent,"NT 4")>0 then
SystemVer="Windows NT4"
elseif Instr(agent,"4.9")>0 then
SystemVer="Windows ME"
elseif Instr(agent,"98")>0 then
SystemVer="Windows 98"
elseif Instr(agent,"95")>0 then
SystemVer="Windows 95"
else
SystemVer="未知"
end if
operationsystem="操作系统: " & SystemVer
end function

在ASP中,可以使用requst对象的ServerVariables方法来获取客户端的浏览器的版本。自定义函数:
function browser() '浏览器版本
agent = Request.ServerVariables("HTTP_USER_AGENT")
if Instr(agent,"MSIE 6.0")>0 then
browserVer="Internet Explorer 6.0"
elseif Instr(agent,"MSIE 5.5")>0 then
browserVer="Internet Explorer 5.5"
elseif Instr(agent,"MSIE 5.01")>0 then
browserVer="Internet Explorer 5.01"
elseif Instr(agent,"MSIE 5.0")>0 then
browserVer="Internet Explorer 5.00"
elseif Instr(agent,"MSIE 4.0")>0 then
browserVer="Internet Explorer 4.0"
else
browserVer="未知"
end if
browser="浏览器: " & browserVer
if Instr(agent,"TencentTraveler")>0 then '检查是否正在使用腾讯TT
browser=browser&" |目前正使用TencentTraveler"
end if
end function

一、关于IE版本
Request.ServerVariables("HTTP_USER_AGENT")

二、客户端操作系统版本

自定义函数:
function operationsystem() '操作系统版本
agent = Request.ServerVariables("HTTP_USER_AGENT")
if Instr(agent,"NT 5.1")>0 then
SystemVer="Windows XP"
elseif Instr(agent,"NT 5")>0 then
SystemVer="Windows 2000"
elseif Instr(agent,"NT 4")>0 then
SystemVer="Windows NT4"
elseif Instr(agent,"4.9")>0 then
SystemVer="Windows ME"
elseif Instr(agent,"98")>0 then
SystemVer="Windows 98"
elseif Instr(agent,"95")>0 then
SystemVer="Windows 95"
else
SystemVer="未知"
end if
operationsystem="操作系统: " & SystemVer
end function

获取客户端IP、浏览器和操作系统信息的几种方法

<p align=center>获取客户端浏览器和操作系统信息的几种方法</p>

<Script language=Vbscript>

''=首先---穷举法:用VBS中的Navigator.appVersion(或者.UserAgent)属性=
''=此种方法可以在客户端显示,但是不可以保存到服务器端数据库里=

Document.write Navigator.appVersion&"<p>"

Function Browser(Info)
Info=Navigator.appVersion ''在这里初始化了Info,在实际应用中可以作为其他变量赋值
If InStr(Info,"MSIE 6")>0 Then
Browser="Internet Explorer 6.0"
ElseIf InStr(Info,"MSIE 5.5")>0 Then
Browser="Internet Explorer 5.5"
ElseIf InStr(Info,"MSIE 5.0")>0 Then
Browser="Internet Explorer 5.0"
ElseIf InStr(Info,"MSIE 4")>0 Then
Browser="Internet Explorer 4.0"
Else
Browser="未知的浏览器!"
End if
Document.Write "您的浏览器是:"&Browser&"<p>"
End Function

Function System(Info)
Info=Navigator.appVersion
If InStr(Info,"NT 5.1")>0 Then
System="Windows XP"
ElseIf InStr(Info,"NT 5.0")>0 Then
System="Windows 2000"
ElseIf InStr(Info,"NT 4")>0 Then
System="Windows NT"
ElseIf InStr(Info,"98")>0 Then
System="Windows 98"
ElseIf InStr(Info,"Me")>0 Then
System="Windows Me"
ElseIf InStr(Info,"95")>0 Then
System="Windows 95"
Else
System="未知的操作系统!"
End if
Document.Write "您的操作系统是:"&System&"<p>"
End Function

Call Browser(Info)
Call System(Info)

</Script>

------------------------------------------------------------<p>

<%
''=其次:用Request.ServerVariables("Http_User_Agent")=

Response.Write Request.ServerVariables("Http_User_Agent")&"<p>"

Function Browser(Info)
Info=Request.ServerVariables("Http_User_Agent") ''在这里初始化了Info,在实际应用中可以作为其他变量赋值
If InStr(Info,"MSIE 6")>0 Then
Browser="Internet Explorer 6.0"
ElseIf InStr(Info,"MSIE 5.5")>0 Then
Browser="Internet Explorer 5.5"
ElseIf InStr(Info,"MSIE 5.0")>0 Then
Browser="Internet Explorer 5.0"
ElseIf InStr(Info,"MSIE 4")>0 Then
Browser="Internet Explorer 4.0"
Else
Browser="未知的浏览器!"
End if
Response.Write "您的浏览器是:"&Browser&"<p>"
End Function

Function System(Info)
Info=Request.ServerVariables("Http_User_Agent")
If InStr(Info,"NT 5.1")>0 Then
System="Windows XP"
ElseIf InStr(Info,"NT 5.0")>0 Then
System="Windows 2000"
ElseIf InStr(Info,"NT 4")>0 Then
System="Windows NT"
ElseIf InStr(Info,"98")>0 Then
System="Windows 98"
ElseIf InStr(Info,"Me")>0 Then
System="Windows Me"
ElseIf InStr(Info,"95")>0 Then
System="Windows 95"
Else
System="未知的操作系统!"
End if
Response.Write "您的操作系统是:"&System&"<p>"
End Function

Call Browser(Info)
Call System(Info)

%>

===========================================================<p>

<%
''第三种方法:在appVersion/UserAgent或Request.ServerVariables("Http_User_Agent")
''=之中截取固定的字符串,把有关浏览器和操作系统的字符串截取出并显示=
''=显然问题在于,如果某一天Microsoft把浏览器版本的格式改变了,那么此方法会出错
''=格式:浏览器版本-左数第31个字符起3个字符,系统版本-左数第44个字符起6个字符

Response.Write Request.ServerVariables("Http_User_Agent")&"<p>"

Function Browser2(Info)
Info=Request.ServerVariables("Http_User_Agent")
If InStr(Info,"MSIE")>0 Then ''判断当前浏览器是否是"Microsoft IE"类型
Version=Mid(Info,31,3)
IE="Internet Explorer"
Response.Write "您的浏览器是:"&IE&" "&Version&"<p>"
Else
Response.Write "您的浏览器是:未知的浏览器"
End if
End Function

Function System2(Info)
Info=Request.ServerVariables("Http_User_Agent")
If InStr(Info,"Windows")>0 Then ''判断当前操作系统是否是"Windows"平台
Version=Mid(Info,44,6)
Plat="Windows"
''下面还要进行判断版本,以供显示具体的平台
If InStr(Version,"NT 5.1")>0 Then
Plat="Windows XP"
ElseIf InStr(Version,"NT 5.0")>0 Then
Plat="Windows 2000"
ElseIf InStr(Version,"NT 4")>0 Then
Plat="Windows NT"
ElseIf InStr(Version,"98")>0 Then
Plat="Windows 98"
ElseIf InStr(Version,"Me")>0 Then
Plat="Windows Me"
ElseIf InStr(Version,"95")>0 Then
Plat="Windows 95"
Else
Plat="未知的操作系统!"
End if
Response.Write "您的操作系统是:"&Plat&"<p>"
Else
Response.Write "您的操作系统是:未知的操作系统"
End if
End Function

Call Browser2(Info)
Call System2(Info)

%>

----------------------------------------------------------<p>

<Script Language=VBscript>

Document.Write Navigator.appVersion&"<p>"

Function Browser2(Info)
Info=Navigator.appVersion
If InStr(Info,"MSIE")>0 Then ''判断当前浏览器是否是"Microsoft IE"类型
Version=Mid(Info,23,3)
IE="Internet Explorer"
Document.Write "您的浏览器是:"&IE&" "&Version&"<p>"
Else
Document.Write "您的浏览器是:未知的浏览器"
End if
End Function

Function System2(Info)
Info=Navigator.appVersion
If InStr(Info,"Windows")>0 Then ''判断当前操作系统是否是"Windows"平台
Version=Mid(Info,36,6)
Plat="Windows"
''下面还要进行判断版本,以供显示具体的平台
If InStr(Version,"NT 5.1")>0 Then
Plat="Windows XP"
ElseIf InStr(Version,"NT 5.0")>0 Then
Plat="Windows 2000"
ElseIf InStr(Version,"NT 4")>0 Then
Plat="Windows NT"
ElseIf InStr(Version,"98")>0 Then
Plat="Windows 98"
ElseIf InStr(Version,"Me")>0 Then
Plat="Windows Me"
ElseIf InStr(Version,"95")>0 Then
Plat="Windows 95"
Else
Plat="未知的操作系统!"
End if
Document.Write "您的操作系统是:"&Plat&"<p>"
Else
Document.Write "您的操作系统是:未知的操作系统"
End if
End Function

Call Browser2(Info)
Call System2(Info)

</Script>

=============================================<p>

<%
''========另外,有人提出利用ASP的ActiveX组件MSWC.BrowserType的属性来实现==========
''========现在问题是,IE 6.0以上版本的这个组件还没有更新,因此随意使用会出错=====
''========我们不提倡这种方法=====================================================
Dim BT
Set BT=Server.CreateObject("MSWC.BrowserType")
Response.Write BT.Browser&"<br>"
Response.Write BT.Version&"<br>"
Response.Write BT.PlatForm&"<br>"
%>

<p align=center>获得客户端IP的方法</p>

<%
''此参数是取得透过代理服务器的客户端IP
IP=Request.ServerVariables("Http_X_ForWarded_For")
If Len(IP)=0 Then
Response.write "非代理服务器:空<p>"
''直接取得客户端的IP
IP=Request.ServerVariables("Remote_Addr")
Response.write "代理服务器:"&IP
Else
Response.write "非代理服务器:"&IP&"<p>"
End If

%>