Forum Moderators: coopster

Message Too Old, No Replies

php style sheet switching

         

doozer77

2:30 pm on May 28, 2005 (gmt 0)

10+ Year Member



I would like to write a script that will determine which browser/platform a user is on and then select the proper style sheet. I've done this before only to select either a style sheet for IEWin or the default style sheet. This is the code I used:

<?php
$useragent = (isset($_SERVER["HTTP_USER_AGENT"]) )?
$_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT;

if (strpos($useragent, 'MSIE')) {
$css_file = '/style_ie.css';
} else {
$css_file = '/style.css';
}
?>

But now I want to be able to determine the difference not only between IE and other browsers but also Mac and PC. The above script will only recognize a single word as the string. (does this make sense?)

For instance, here's the results from my computer running the above script:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)

and on a friend's MAC it's:

Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)

It seems I wold need to select both the 'MSIE' part and the 'Windows' or 'Mac_PowerPC' part from the script to select the style sheet.

Does anyone know how to write a script to select both parts of the ($_SERVER["HTTP_USER_AGENT"]) result? Have I even made sense here?

bronze

8:25 pm on May 28, 2005 (gmt 0)

10+ Year Member



[sitepoint.com...]
This browser detect script can help to you.