BoltZ Posted October 27, 2008 Share Posted October 27, 2008 <?php if ($_SERVER['HTTP_USER_AGENT'] == "Mozilla Firefox") { echo '<link rel="stylesheet" type="text/css" href="stylesheet.css" />'; } else if ($_SERVER['HTTP_USER_AGENT'] == "Microsoft Internet Explorer") { echo '<link rel="stylesheet" type="text/css" href="iestyle.css" />'; } ?> This code does not print any stylesheet for any browser. What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/130351-echo-diff-stylesheets-dependin-on-browser/ Share on other sites More sharing options...
rhodesa Posted October 27, 2008 Share Posted October 27, 2008 first, the HTTP_USER_AGENT is not simply "Mozilla Firefox" or "Microsoft Internet Explorer". you could set up get_browser(), which will translate the user agent into something you can work with: http://us3.php.net/function.get-browser read the Notes section for how to set up browsercap.ini the other option is to use the more common method. this involves coding it to work in firefox, then having an IE conditional comment. more info on that is here: http://www.quirksmode.org/css/condcom.html BUT, i'm curious as to why you need different CSS files. usually if you think you need separate files, you are doing something wrong. you should be able to do it all with one CSS file. Quote Link to comment https://forums.phpfreaks.com/topic/130351-echo-diff-stylesheets-dependin-on-browser/#findComment-676092 Share on other sites More sharing options...
BoltZ Posted October 27, 2008 Author Share Posted October 27, 2008 hmm i think ill just use javascript and if javascript is disabled then echo the original stylesheet Quote Link to comment https://forums.phpfreaks.com/topic/130351-echo-diff-stylesheets-dependin-on-browser/#findComment-676108 Share on other sites More sharing options...
kenshintomoe225 Posted October 27, 2008 Share Posted October 27, 2008 I would go with get_browser(), you might as well! Quote Link to comment https://forums.phpfreaks.com/topic/130351-echo-diff-stylesheets-dependin-on-browser/#findComment-676125 Share on other sites More sharing options...
BoltZ Posted October 27, 2008 Author Share Posted October 27, 2008 You convinced me my older friend. It makes sense since this will be a bulletin board system code I will have to make sure it is usable by everyone and not what is easier for me to code. I shall go research this get_browser function. (man you wouldnt believe the kind of stuff I have learned from trying to create forums, i definately recommend people trying it) Quote Link to comment https://forums.phpfreaks.com/topic/130351-echo-diff-stylesheets-dependin-on-browser/#findComment-676152 Share on other sites More sharing options...
rhodesa Posted October 28, 2008 Share Posted October 28, 2008 to get get_browser() working, you need to download this file: http://browsers.garykeith.com/stream.asp?Lite_PHP_BrowsCapINI save it somewhere (i saved it in the 'extras' folder where PHP is installed). then update this line in your php.ini file: browscap = /path/to/browscap.ini Quote Link to comment https://forums.phpfreaks.com/topic/130351-echo-diff-stylesheets-dependin-on-browser/#findComment-676178 Share on other sites More sharing options...
Jeremysr Posted October 28, 2008 Share Posted October 28, 2008 I would just do this: <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) { echo '<link rel="stylesheet" type="text/css" href="stylesheet.css" />'; } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { echo '<link rel="stylesheet" type="text/css" href="iestyle.css" />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130351-echo-diff-stylesheets-dependin-on-browser/#findComment-676179 Share on other sites More sharing options...
BoltZ Posted October 28, 2008 Author Share Posted October 28, 2008 Your a genius! Worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/130351-echo-diff-stylesheets-dependin-on-browser/#findComment-676224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.