Link to home
Start Free TrialLog in
Avatar of dantheriver
dantheriver

asked on

Determine OS and Browser from HTTP_User_Agent

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?
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

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
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
ASKER CERTIFIED SOLUTION
Avatar of ajaikumarr
ajaikumarr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ajaikumarr
ajaikumarr

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
>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.

Might beef it up with Ajai's code if Ajai doesn't mind.
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.
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
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>
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
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.

Rod,

Thanks :)

Bye
Ajai