?
Solved

Browser Detection / Redirection : (pointer to original Q - 125 pts)

Posted on 2004-08-11
1
Medium Priority
?
259 Views
Last Modified: 2013-12-24
0
Comment
Question by:stu215
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
rlavalle earned 80 total points
ID: 11785615
Here you go...

Here'a solution using ColdFusion and a tiny bit of JavaScript. ColdFusion has a CGI variable called HTTP_USER_AGENT that holds the browser name and version near the end. I parse this string and check for each of the 3 browser types and their version. You can easily open a ColdFusion page in any browser you want to compare against and determine where in the HTTP_USER_AGENT string the browser name and version is (in case you need to change this in the future).

Oh, and I used the latest version of Safari that I think has been released (125.9) rather than 128.5.

Good luck,
Russ

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<cfscript>

function IsBrowserValid()
{
     browserLoc = 0;
     versNum = 0;
     safari = "Safari";
     msie = "MSIE";
     netscape = "Netscape";
     goodBrowser = false;
     
     browserLoc = FindNoCase(safari, CGI.HTTP_USER_AGENT);
     if (browserLoc)
     {
          versNum = Val(RemoveChars(CGI.HTTP_USER_AGENT, 1, browserLoc + LEN(safari)));
          if (versNum GTE 125.9)
               goodBrowser = true;
     }
     else
     {
          browserLoc = FindNoCase(msie, CGI.HTTP_USER_AGENT);
          if (browserLoc)
          {
               versNum = Val(RemoveChars(CGI.HTTP_USER_AGENT, 1, browserLoc + LEN(msie)));
               if (versNum GTE 6)
                    goodBrowser = true;
          }
          else
          {
               browserLoc = FindNoCase(netscape, CGI.HTTP_USER_AGENT);
               if (browserLoc)
               {
                    versNum = Val(RemoveChars(CGI.HTTP_USER_AGENT, 1, browserLoc + LEN(netscape)));
                    if (versNum GTE 7)
                         goodBrowser = true;
               }
          }
     }
     
     return goodBrowser;
}
</cfscript>

<script language="javascript1.2">
<cfif IsBrowserValid()>
          alert('Browser is valid. You may continue.');
<cfelse>
          alert('Browser is INVALID. You must go away.');
          window.location = "http://www.google.com";
</cfif>
</script>

</body>
</html>
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

801 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