At 11/14/2006 08:00 PM, Ed Lazor wrote:
I'm reading a book on CSS and how you can define different style
sheets for different visitors. I'm wondering how you guys do it.
The book recommends using Javascript functions for identifying the
user's browser and matching them with the corresponding style
sheets. Anyone using PHP for this instead - specifically with
defining style sheets for different target browsers and platforms?
The simple answer to your question is that you can get a browser's
calling card with $_SERVER['HTTP_USER_AGENT'] which will report, for
example, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1)
Gecko/20061010 Firefox/2.0" -- leaving you free to parse to guess at
what user agent generated it.
However, the street-wise programmer doesn't use JavaScript or PHP or
any other language to determine browser type based on HTTP_USER_AGENT
because that field can be and is so easily and routinely
spoofed. It's better to let a browser's own innate abilities be the filter.
For example, IE and only IE responds to Microsoft's conditional
comments such as:
<!--[if IE 6]>
serve something only to Internet Explorer 6
<![endif]-->
http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp
If you'll tell us why you want to serve different stylesheets to
different visitors, you're sure to get suggestions for how to write
your CSS to sidestep browser differences and/or how to write hacks
which identity browsers by their idiosyncratic bugs.
This topic will be much better received in a CSS listserve such as
CSS-D. Before you post, check their wiki for plentiful suggestions:
http://css-discuss.incutio.com/
and specifically:
http://css-discuss.incutio.com/?page=BrowserDetection
Regards,
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php