.php css switcher
- Started
- Last post
- 13 Responses
- elPaulo
Hey all. Having a hard time troubleshooting this file. I have a site in testing, and am beginning to develop the browser specific stylesheets. But, my .php switcher aint doing it. Anyone here able to tell me what is wrong with this:
________________________________...
<?php function switchCSS() { //$browser = $_SERVER['HTTP_USER_AGENT']; // echo $_SERVER['HTTP_USER_AGENT'] . "\n\n"; $browser = get_browser($_SERVER['HTTP_USER_AGENT']); //echo $browser . "\n\n"; if (stripos( $browser, "MSIE 7.0" ) === true) { echo "<link rel='stylesheet' type='text/css' media='screen' href='css/ie7.css' />";
}
else if (stripos( $browser, "Firefox/3.0" ) === true) {
echo "<link rel='stylesheet' type='text/css' media='screen' href='stylesheets/firefox.css' />";
}
else if (stripos( $browser, "MSIE 6" ) === true) {
echo "<link rel='stylesheet' type='text/css' media='screen' href='css/ie6.css' />";
}
else {
echo "<link rel='stylesheet' type='text/css' media='screen' href='css/default.css' />";
}
}
?>
________________________________...Any help is appreciated!
- NONEIS0
Could you be a bit more vague as to the actual issue at hand????
- acescence0
the line
$browser = $_SERVER['HTTP_USER_AGENT'];
is commented out?
- acescence0
oh wait, there's another in there. this is confusing hold on...
- acescence0
are you actually calling this function from somewhere? it's not going to do anything unless you call the function
switchCSS();
somewhere outside of the function def
- elPaulo0
sorry folks. Burned out I guess.
The deal is, is that when this page loads (http://www.shopalponte.com/paul... no matter what browser, the .php script points it at the default.css, and not the specific one. So, for instance, when viewed in IE6, it still comes up with the default.css, rather than ie6.css.
Make sense?
- elPaulo0
yeah, this call is in the <head> on every page:
<?php require_once 'switchcss.php'; ?>
- elPaulo0
why wont my link paste?!!!! AAARRGGHHHHH
- acescence0
i'm confused. just including the file doesn't call the function, you need to add a call to the function like:
switchCSS();
after the last bracket, or remove:
function switchCSS() {
and the closing } at the end. it doesn't make sense that it would work at all, unless there's part of the php file missing here?also- the get_browser function returns an array of all the browsers capabilities, this isn't something that is normally used for browser sniffing, i think you just need the HTTP_USER_AGENT. hold on, let me whip something up for you..
- BabySnakes0
wouldn't JS be nicer way to do it?
- acescence0
this might work for you...
my Win box is dead right now, so I only tested with FF/Mac. the part that might be funky is the version numbers, i'm not sure if ie returns "7.0" or just "7", so you might have to tweak that. uncomment the 2 lines that print the browser/version so you can see what's getting returned
- heavyt0
you have a funciton which may or may not be being called. You also have a func call inside that func, which may or may not exist (get_browser).
My guess - you "borrowed" some code, but missed a bunch.
- elPaulo0
nah, actually, I didnt rip it. I developed it with a friend. We re"worded" it and its running fine now.
Kinda glad we got it done. Be able to use it on a lot of sites now.