?
Solved

Determine OS and Browser from HTTP_User_Agent

Posted on 2005-04-26
13
Medium Priority
?
495 Views
Last Modified: 2011-09-20
We are currently using BrowserHawk to determine the environment of users of our web application. The only data that I really need to collect is the users OS and Browser. Browser Hawk is overkill for what we need, and rather than renewing our Expensive subscription with them, I am looking for a reliable way to just parse the OS and browser out of the HTTP_USER_AGENT. Does anyone know of a good way to do this or any alternative componenets to browserhawk?
0
Comment
Question by:dantheriver
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13867414
I use code like this to see what is really available:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>

<body>
<%
For each objItem in Request. ServerVariables
      Response.write(objItem & ": " & Request.ServerVariables(objItem) & "<br>")
Next
%>
</body>
</html>


FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13867483
Finally, if you keep your browscap.ini file up to date, you can use that to get all of the information easily and reliably:

http://www.abiglime.com/webmaster/articles/asp/121798.htm

FtB
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
ajaikumarr earned 1000 total points
ID: 13869107
Hai,
Try this.

<%
ClientIn = Request.Servervariables("HTTP_USER_AGENT")
Response.write "Client OS         :" & GetClientOS(ClientIn) & "<br>"
Response.write "Client Browser :" & GetBrowserVersion(ClientIn) & "<br>"
Response.write "<br><br><br>"

Function GetClientOS(byval ClientIn)
      if Instr(ClientIn, "Windows NT 5.0")>0 or Instr(ClientIn, "Windows 2000")>0 then
            GetClientOS = "Windows 2000"
      elseif Instr(ClientIn, "Windows NT 5.1")>0 or Instr(ClientIn, "Windows XP")>0 then
            GetClientOS = "Windows XP"
      elseif Instr(ClientIn, "Me")>0 or Instr(ClientIn, "Windows ME")>0  or Instr(ClientIn, "Win9x")>0 or Instr(ClientIn, "Win 9x")>0 then
            GetClientOS = "Windows ME"
      elseif Instr(ClientIn,  "Windows NT")>0  or Instr(ClientIn, "WinNT")>0 then
            GetClientOS = "Windows NT"
      elseif Instr(ClientIn, "Windows 98")>0 or Instr(ClientIn, "Win98")>0 then
            GetClientOS = "Windows 98"
      elseif Instr(ClientIn, "Windows 95")>0 or Instr(ClientIn, "Win95")>0 then
            GetClientOS = "Windows 95"
      elseif Instr(ClientIn, "Mac")>0 then
            GetClientOS = "Mac OS"
      elseif Instr(ClientIn, "Sun")>0 then
            GetClientOS = "Sun OS"
      elseif Instr(ClientIn, "Linux")>0 then
            GetClientOS = "Linux"
      elseif Instr(ClientIn, "Unix")>0 then
            GetClientOS = "Unix"
      elseif Instr(ucase(ClientIn), "WEBTV")>0 then
            GetClientOS = "Web TV"
      elseif Instr(ucase(ClientIn), "AIX")>0 then
            GetClientOS = "AIX"
      elseif Instr(ucase(ClientIn), "OPENVMS")>0 then
            GetClientOS = "Open VMS"
      elseif Instr(ucase(ClientIn), "OS/2")>0 then
            GetClientOS = "OS/2"
      else
            GetClientOS = "Undetermined"
      end if
End Function

Function GetBrowserVersion(byval ClientIn)
      dim ivlBrowser, BrowserVersion
      if Instr(ClientIn, "MSIE")>0 then      'Internet Explorer
            BrowserVersion = GetIEVersion(ClientIn)
            ivlBrowser = Left(Trim(Replace(BrowserVersion & "", ".", "")) & "00", 2)
            if not IsNumeric(ivlBrowser) then ivlBrowserVersion = "60"
            if ivlBrowser >= 60 then
                  GetBrowserVersion = "IE 6.0"
            elseif ivlBrowser >= 55 then
                  GetBrowserVersion = "IE 5.5"
            elseif ivlBrowser >= 50 then
                  GetBrowserVersion = "IE 5.0"
            elseif ivlBrowser >= 40 then
                  GetBrowserVersion = "IE 4.0"
            else
                  GetBrowserVersion = "Other IE versions"
            end if
      elseif Instr(ClientIn, "Netscape")>0 or instr(ucase(ClientIn), "C-CCK-MCD")>0  or instr(ucase(ClientIn), "GECKO")>0 or instr(ucase(ClientIn), "C-NECCK")>0 then
            GetBrowserVersion = "Netscape"
      elseif Instr(ClientIn, "Opera")>0 then
            GetBrowserVersion = "Opera"
      elseif instr(ClientIn, "Mozilla")>0 then      'Mozilla Agent; Probably Netscape, but may not be..
            GetBrowserVersion = "Mozilla"
      else
            GetBrowserVersion = "Undetermined"
      end if
End Function
%>

Bye
Ajai
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 13869141
Hai,

Also add these to your page

Function GetIEVersion(strData)
      dim x, y
      
      GetIEVersion=0
      x=instr(1, strData,"MSIE")+4
      y=instr(x,strData,";")
      if x>0 and Y>0 and Y>x then
            GetIEVersion=mid(strData,x,y-x)
      end if
end function

Bye
Ajai
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13870191
>or any alternative componenets to browserhawk?

http://www.rodsdot.com/ee/browser_test.asp

Was put together from various EE questions from users requesting how to test browser capabilities.  It is overkill for your question, but might save you from an expensive renewal.  It isn't nearly as capable as BrowserHawk, but it does demo how to test for many common browser capabilities.

0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13870194
Might beef it up with Ajai's code if Ajai doesn't mind.
0
 
LVL 13

Expert Comment

by:jrram
ID: 13872200
rdivilbiss,

Where can you download the code for (http://www.rodsdot.com/ee/browser_test.asp).  Or do you just use the javascript on that page?  I didn't see any code that makes the alert box come up when you load the page so I assume there was something else behind it.
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13872395
The code is in the box with the yellow background.  Look closely...it isn't all JavaScript.  Most of it is, but not all.

There is a cookies.js file and a java applet.

The cookies.js file can be found at:
Published on: Saturday 21st February 1998 By: Martin Webb
tech.irt.org/articles/js064
www.deletemycookies.com/intelligentcookies.htm

The java applet can be had here:
Published by Michael Horowitz
http://javatester.org/version.html
http://www.michaelhorowitz.com/javatester.results.html

I don't distribute those, but only point you to the copyright holders page, where you may obtain them in accordance with their respective copyright requirements.

Regards,
Rod
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13872415
Just in case something is missing from the code box:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<title>Browser Test</title>
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005 Roderick Divilbiss">
<!-- Intelligent Cookies -->
<!-- Published on: Saturday 21st February 1998 By: Martin Webb -->
<!-- tech.irt.org/articles/js064 -->
<!-- www.deletemycookies.com/intelligentcookies.htm -->
<script language="javascript" type="text/javascript" src="../include/cookies.js"></script>

<script language="javascript" type="text/javascript">
<!--
document.writeln('<pre><strong>JavaScript is enabled</strong></pre>');
storeMasterCookie();
storeIntelligentCookie("TEST","Cookie Accepted");
if (Get_Cookie("TEST")!=null) {
    document.writeln('<pre><strong>'+Get_Cookie("TEST")+'</strong></pre>');
} else {
    document.writeln('<pre><strong>COOKIE REFUSED</strong></pre>');
}
if (navigator.javaEnabled()==true) {
      document.writeln('<pre><strong>Java Enabled</strong></pre>');
      document.writeln('<div id="javaver">Testing....</div>');
}else{
      document.writeln('<pre><strong>No Java</strong></pre>');
}
var myVal = 5;
function pSuccess() {
      if (myVal==0) {
            document.getElementById('popres').innerHTML = '<pre><strong>POPUP WORKED</strong></pre>';
            return true;
      } else {
            document.getElementById('popres').innerHTML = '<pre><strong>POPUP BLOCKED</strong></pre>';
            return false;
      }
}
var popup = window.open('testpop.asp','test');
      if (popup.opener == null) popup.opener = self;
setTimeout('pSuccess()',1000);
function flashInstalled()
{
      result = false;
      if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
      {
            result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
      }
      else if (document.all && (navigator.appVersion.indexOf("Mac")==-1))
      {
            // IE Windows only -- check for ActiveX control, have to hide code in eval from Netscape (doesn't like try)
            eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj)      result = true; xObj = null;      } catch (e)      {}');
      }
      return result;
}
if (flashInstalled()) {
    document.writeln('<pre><strong>Flash: </strong>Installed</pre>');
} else {
    document.writeln('<pre><strong>Flash: </strong>Missing</pre>');
}
document.writeln('<pre><strong>Screen Size: </strong> '+screen.width+'X'+screen.height+'</pre>');
document.writeln('<pre><strong>Color Depth: </strong> '+screen.colorDepth+' bit</pre>');
document.writeln('<pre><strong>Available Window: </strong> '+screen.availHeight+'X'+screen.availWidth+'</pre>');

//-->
</script>
<noscript>
      <pre><strong>JavaScript is disabled.</strong></pre>
</noscript>
<title>Browser Test</title>
<style>
<!--
#code {
      border: 1px solid #000000;
      padding-left:10px;
      padding-right:10px;
      padding-top:10px; background-color:#FFFFCC
      }
-->
</style>
</head>

<body>
<!-- Published by Michael Horowitz -->
<!-- http://javatester.org/version.html -->
<!-- http://www.michaelhorowitz.com/javatester.results.html -->

<APPLET codeBase="." height="0" width="0"
    code="JavaVersionDisplayApplet.class"
    name="display"
    mayscript VIEWASTEXT>
</APPLET>
<div id="popres">Testing....</div>
<script type="text/vbscript" language="vbscript">
  on error resume next
  msgbox("VBScript is enabled")
</script>
<noscript>
      <pre><strong>VB Script is disabled.</strong></pre><br>
</noscript>
<%
response.write("<pre>")
for each item in request.servervariables
      response.write "<strong>" & item & ": <strong>" & request.servervariables(item) & "<br>"
next
%>
<script>
var app = document.applets[0];
var version = app.getVersion();
var vendor = app.getVendor();
if (version!=null) {
      document.getElementById('javaver').innerHTML = '<pre><strong>Version: </strong>'+vendor+' '+version+'</pre>';
} else {
      document.getElementById('javaver').innerHTML = '<pre><strong>Version: </strong>Unable To Detect</pre>';
}
var i_activex;
</script>
<script type="text/vbscript">
on error resume next
      i_activex = IsObject(CreateObject("Microsoft.ActiveXPlugin.1"))
</script>
<div id="code"><pre>
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd">;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;Browser Test&lt;/title&gt;<br>&lt;meta name=&quot;author&quot; content=&quot;Roderick Divilbiss&quot;&gt;<br>&lt;meta name=&quot;copyright&quot; content=&quot;© 2005 Roderick Divilbiss&quot;&gt;<br>
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;../include/cookies.js&quot;&gt;&lt;/script&gt;<br>&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;<br>&lt;!--<br>document.writeln('&lt;pre&gt;&lt;strong&gt;JavaScript is enabled&lt;/strong&gt;&lt;/pre&gt;');<br>
storeMasterCookie();<br>storeIntelligentCookie(&quot;TEST&quot;,&quot;Cookie Accepted&quot;);<br>if (Get_Cookie(&quot;TEST&quot;)!=null) {<br>    document.writeln('&lt;pre&gt;&lt;strong&gt;'+Get_Cookie(&quot;TEST&quot;)+'&lt;/strong&gt;&lt;/pre&gt;');<br>} else {<br>    document.writeln('&lt;pre&gt;&lt;strong&gt;COOKIE REFUSED&lt;/strong&gt;&lt;/pre&gt;');<br>
}<br>
if (navigator.javaEnabled()==true) {<br>    document.writeln('&lt;pre&gt;&lt;strong&gt;Java Enabled&lt;/strong&gt;&lt;/pre&gt;');<br>    document.writeln('&lt;div id=&quot;javaver&quot;&gt;Testing....&lt;/div&gt;'); <br>
}else{<br>    document.writeln('&lt;pre&gt;&lt;strong&gt;No Java&lt;/strong&gt;&lt;/pre&gt;');<br>
}<br>
var myVal = 5;<br>
function pSuccess() {<br>    if (myVal==0) {<br>        document.getElementById('popres').innerHTML = '&lt;pre&gt;&lt;strong&gt;POPUP WORKED&lt;/strong&gt;&lt;/pre&gt;';<br>        return true;<br>    } else {<br>        document.getElementById('popres').innerHTML = '&lt;pre&gt;&lt;strong&gt;POPUP BLOCKED&lt;/strong&gt;&lt;/pre&gt;';<br>        return false;<br>    }<br>
}<br>
var popup = window.open('testpop.asp','test');<br>if (popup.opener == null) popup.opener = self;<br>setTimeout('pSuccess()',1000);<br>
function flashInstalled() {<br>    result = false;<br>    if (navigator.mimeTypes &amp;&amp; navigator.mimeTypes[&quot;application/x-shockwave-flash&quot;]){<br>        result = navigator.mimeTypes[&quot;application/x-shockwave-flash&quot;].enabledPlugin;<br>    }<br>    else if (document.all &amp;&amp; (navigator.appVersion.indexOf(&quot;Mac&quot;)==-1)) {<br>        // IE Windows only -- check for ActiveX control, have to hide code in eval from Netscape (doesn't like try)<br>        eval ('try {var xObj = new ActiveXObject(&quot;ShockwaveFlash.ShockwaveFlash&quot;);if (xObj) result = true; xObj = null; } catch (e) {}');<br>    }<br>    return result;<br>
}<br>
if (flashInstalled()) {<br>    document.writeln('&lt;pre&gt;&lt;strong&gt;Flash: &lt;/strong&gt;Installed&lt;/pre&gt;');<br>} else {<br>    document.writeln('&lt;pre&gt;&lt;strong&gt;Flash: &lt;/strong&gt;Missing&lt;/pre&gt;');<br>
}<br>
document.writeln('&lt;pre&gt;&lt;strong&gt;Screen Size: &lt;/strong&gt; '+screen.width+'X'+screen.height+'&lt;/pre&gt;');<br>document.writeln('&lt;pre&gt;&lt;strong&gt;Color Depth: &lt;/strong&gt; '+screen.colorDepth+' bit&lt;/pre&gt;');<br>document.writeln('&lt;pre&gt;&lt;strong&gt;Available Window: &lt;/strong&gt; '+screen.availHeight+'X'+screen.availWidth+'&lt;/pre&gt;');<br><br>
//--&gt;<br>
&lt;/script&gt;<br>&lt;noscript&gt;<br>    &lt;pre&gt;&lt;strong&gt;JavaScript is disabled.&lt;/strong&gt;&lt;/pre&gt;<br>&lt;/noscript&gt;<br><br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;APPLET codeBase=&quot;.&quot; height=&quot;0&quot; width=&quot;0&quot; <br>code=&quot;JavaVersionDisplayApplet.class&quot; <br>name=&quot;display&quot; <br>mayscript VIEWASTEXT&gt;<br>&lt;/APPLET&gt;<br>
&lt;div id=&quot;popres&quot;&gt;Testing....&lt;/div&gt;<br>&lt;script type=&quot;text/vbscript&quot; language=&quot;vbscript&quot;&gt;<br>    on error resume next<br>    msgbox(&quot;VBScript is enabled&quot;)<br>&lt;/script&gt;<br>&nbsp;</pre>
      <pre>
&lt;%<br>response.write(&quot;&lt;pre&gt;&quot;)<br>for each item in request.servervariables<br>    response.write &quot;&lt;strong&gt;&quot; &amp; item &amp; &quot;: &lt;strong&gt;&quot; &amp; request.servervariables(item) &amp; &quot;&lt;br&gt;&quot;<br>
next<br>%&gt;<br>
&lt;script&gt;<br>var app = document.applets[0];<br>var version = app.getVersion();<br>var vendor = app.getVendor();<br>if (version!=null) {<br>    document.getElementById('javaver').innerHTML = '&lt;pre&gt;&lt;strong&gt;Version: &lt;/strong&gt;'+vendor+' '+version+'&lt;/pre&gt;';<br>} else {<br>    document.getElementById('javaver').innerHTML = '&lt;pre&gt;&lt;strong&gt;Version: &lt;/strong&gt;Unable To Detect&lt;/pre&gt;';<br>
}<br>
var i_activex;
&lt;/script&gt;<br>
&lt;script type=&quot;text/vbscript&quot;&gt;<br>    on error resume next<br>    i_activex = IsObject(CreateObject(&quot;Microsoft.ActiveXPlugin.1&quot;))<br>&lt;/script&gt;</pre>
      <pre>
&lt;/body&gt;
&lt;/html&gt;
</pre></div>
</body>

</html>
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 13872453
Hai rdivilbiss,

You can add those if you need... No probs about that... If possible just add a little bit of credit to my name :)

Bye
Ajai
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13872591
Ajai,

Of course.  Note my care regarding the two libraries I did not write.

jrram,

Correction on the Applet link:

http://support.softartisans.com/kbview_839.aspx (zip file at the bottom of the page.)

Regards,
Rod

BTW: Anybody has a browser test I don't please let me know.

0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 13872623
Rod,

Thanks :)

Bye
Ajai
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question