Re: CSS / PHP / Javascript

From: Date: Wed, 15 Nov 2006 05:49:41 +0000
Subject: Re: CSS / PHP / Javascript
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-244646@lists.php.net to get a copy of this message
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

« previous php.general (#244646) next »