?
Solved

Browser Checking

Posted on 2007-04-10
6
Medium Priority
?
200 Views
Last Modified: 2012-03-15
Can PHP or another programmin language check to see what browser someone is using ? For example can a check be made to see if the browser is IE 6.0, 7.0 or FireFox ?
I need to make some mods to Jinzora (an open source media player). There are some playback issues with some browsers. If I can check for a certain browser then the code will execute the code needed for the particular brwoser/player.

Thanks,
Michael
0
Comment
Question by:mhoggatt1
[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
  • 5
6 Comments
 
LVL 29

Assisted Solution

by:rdivilbiss
rdivilbiss earned 1200 total points
ID: 18884016
$browser = $_SERVER["HTTP_USER_AGENT"];

However, the user agent can be set to anything a person wants and isn't 100% reliable.

http://www.cafesong.com/useragent.php
0
 
LVL 29

Assisted Solution

by:rdivilbiss
rdivilbiss earned 1200 total points
ID: 18884071
http://www.rodsdot.com/ee/browser_test.asp

In ASP it would be browser= Request.ServerVariables("HTTP_USER_AGENT")

In any language you need to filter the user agent for malicious characters or risk XSS and SQL injections.

In any case here is a relatively up to date file of user agents to give you an example of what you are going to see in the real world.

http://www.rodsdot.com/downloads/useragents.zip
0
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 1200 total points
ID: 18884170
Sorry for the disjointed answer...I keep having to answer other questions in the real world.

This should be safe in PHP.

<?PHP
$regExPattern = "/^[a-zA-Z0-9 \;\:\.\-\)\(\/\@\]\[\+\~\_\,\?\=\{\}\*\|\&\#\!]+$/";
preg_match($regExPattern, $_SERVER["HTTP_USER_AGENT"], $arr);
if (!empty($arr)) {
      $browser = $arr[0];
} else {
      $browser = "unknown";
}
echo $browser;
?>
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!

 

Author Comment

by:mhoggatt1
ID: 18884306
Thanks for the replies.
I ran the code from the previous reply and
received this message when I ran it in IE 7.0 -

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)

Is this saying Mozilla is FireFox and why does it list this one first when I'm using IE 7.0 ?

Thanks,
Michael
0
 
LVL 29

Assisted Solution

by:rdivilbiss
rdivilbiss earned 1200 total points
ID: 18884983
Mozilla 4.0 compatible... the browser is IE7, the OS is Windows XP and it gives you the current .NET client installed.

If you download the list of user agents I pointed a link to, you'll see almost all browser user agents begin with Mozilla something.  Mozilla was the mother of all browser engines and nearly all browsers since have started their user agent string with what version of the Mozilla engine they are compatible with.

You'll also be able to use that list to translate from a long user agent to a shorter browser type.  Although it was last updated in December, so there will be a few newer user agents you'll need to add.

0
 
LVL 29

Assisted Solution

by:rdivilbiss
rdivilbiss earned 1200 total points
ID: 18884994
Mine are

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3

which doesn't say FireFox until the very end.

and

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

which shows I have upgraded my .NET client since you had.

and

Opera/9.10 (Windows NT 5.1; U; en)

which gets to the point right away

and

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.9pre) Gecko/20061219 Firefox/1.5.0.9 Flock/0.7.9.1

which is Flock not Firefox,

and

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727) which is lying because it is really Maxthon which is built on top of IE.

and Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; MAXTHON 2.0)

It's all very confusing really.   Don't forget people can lie as well. Some will set their user agents to <script>alert('XSS')</script> just to see if you don't know how to protect your pages.


0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 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