homepage Welcome to WebmasterWorld Guest from 54.166.122.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Cleaner way to display browser version?
How to show "Safari 5" instead of long string of info
floydboy



 
Msg#: 4218991 posted 8:48 pm on Oct 19, 2010 (gmt 0)

All scripts that I can find that detect user browser and version info will give me something like, for example, "Netscape 5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5" instead of "Safari 5". Not pretty. How do sites like [whatbrowser.org ] show it so nicely?

 

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 4218991 posted 7:37 pm on Oct 22, 2010 (gmt 0)

That long string is simply the "user agent" string that the browser sends to identify itself. You don't need a lengthy script to get the user agent, it's just one line of code. eg. in PHP, $_SERVER['HTTP_USER_AGENT'] or in JavaScript, navigator.userAgent.

In order to get something like "Safari 5" you can write a script to intelligently parse the user agent for the appropriate parts you are looking for. This will work OK for the main browsers. If you need to dig deeper and try to identify all browsers / robots / crawlers then you probably need to look up the user agent in some kind of database.

floydboy



 
Msg#: 4218991 posted 8:09 pm on Oct 24, 2010 (gmt 0)

I'm a novice, I don't know how to parse out that info to show... how would I do that?

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 4218991 posted 8:14 am on Oct 25, 2010 (gmt 0)

Depending on the language of choice, you're perhaps better asking this in the appropriate forum... eg.

JavaScript (client-side in the browser):
[webmasterworld.com...]

PHP (Server-side)
[webmasterworld.com...]

milosevic



 
Msg#: 4218991 posted 12:32 pm on Oct 25, 2010 (gmt 0)

In pseudo-code:

if ($user-agent == 'some long string of crap #1') {
$user-agent = 'Safari 5';
}
elseif ($user-agent == 'some long string of crap #2') {
$user-agent = 'IE 6';
}

A smart programmer would use an associative array or at least a switch statement though.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved