Forum Moderators: not2easy
I just developed a nice little stylesheet chooser in php. The idea was that I could link to the script like this..
<link rel="stylesheet" type="text/css" media="all" href="/styles/selector.php">
It could then check what cookie the user had set and just pipe the correct stylesheet through.
Tested it and it worked just fine in Opera7 and IE6. But I couldn't get it to work on NN7. A little further investigation reveals that unless your external stylesheet ends with .css Netscape will simply ignore it.
This seems very wrong to me - I've already told it the mime type of the stylesheet (
type="text/css"), the file extension should be irrelevant.
There are two ways to solve the problem. Either, in your .htaccess file, add php as a text/css mime type. Or, better yet since it's a PHP file, make sure that it prints the text/css header before anything else.
The problem has nothing to do with the extension, just that NN7 doesn't receive a true text/css file :)
Adding
header("Content-Type: text/css") to the php script soon solved the problem. For the record, the final PHP function looks like this..
[pre]
function output_stylesheet( $filename ) {
$content = @file( $filename );
$contentlength = count( $content );
header('Content-Type: text/css');
for ( $line = 0; $line < $contentlength; $line++ ) {
print $content[$line];
}
}
output_stylesheet( 'default.css' );
[/pre]
Of course now I'll expand it a bit so that it selects from a number of different stylesheets based on a cookie setting. That way I can support multiple stylesheets without waiting for Netscape or IE to work properly with the <link rel="alternate stylesheet"> tag.
Plus it seems like a nicer way to handle browser specific sheets.