Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > External stylesheets

Reply
Thread Tools

External stylesheets

 
 
SeeSchloss
Guest
Posts: n/a
 
      09-30-2003
Hi,

I'd like to dynamically generate an external stylesheet
with PHP. Therefore, I replaced the
<link rel="stylesheet" type="text/css" href="style.css" />
with
<link rel="stylesheet" type="text/css" href="style.php" />
(replaced .css with .php).
The problem is that the browser only seems to use the
stylesheet when the extension is '.css', I also tried
'.inc' and a few others, and only '.css' worked (the files
were exactly the same, of course). And since .css files are
not interpreted by PHP (without modifying the config
file)...
Is it normal ? And could you suggest any other way to do it
?
I could make it internal, but since it is about 5KB, it
would almost double the weight of my pages.

Thanks.


--
SeeSchloß - http://www.seeschloss.net

 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      09-30-2003
SeeSchloss wrote:
> I'd like to dynamically generate an external stylesheet
> with PHP. Therefore, I replaced the
> <link rel="stylesheet" type="text/css" href="style.css" />
> with
> <link rel="stylesheet" type="text/css" href="style.php" />
> The problem is that the browser only seems to use the
> stylesheet when the extension is '.css'


File extensions are irrelevant, its the content type in the http header that
browsers (should[1]) respect for deciding what type of file it is. By
default PHP outputs files with a text/html header (which is sensible given
that almost all PHP files are designed to output HTML documents). You have
to explicitly tell it to send a different content type header if you don't
want that.

<?php header('Content-type: text/css'); ?>


[1] Internet Explorer sometimes second guesses the author, I don't know if
file extension plays a role in this.

--
David Dorward http://dorward.me.uk/
 
Reply With Quote
 
 
 
 
SeeSchloss
Guest
Posts: n/a
 
      09-30-2003
David Dorward a écrit :
> SeeSchloss wrote:
>> I'd like to dynamically generate an external stylesheet
>> with PHP. Therefore, I replaced the
>> <link rel="stylesheet" type="text/css" href="style.css" />
>> with
>> <link rel="stylesheet" type="text/css" href="style.php" />
>> The problem is that the browser only seems to use the
>> stylesheet when the extension is '.css'

>
> File extensions are irrelevant, its the content type in the http
> header that browsers (should[1]) respect for deciding what type
> of file it is. By default PHP outputs files with a text/html
> header (which is sensible given that almost all PHP files are
> designed to output HTML documents). You have to explicitly tell
> it to send a different content type header if you don't want
> that.
>
> <?php header('Content-type: text/css'); ?>
>
>
> [1] Internet Explorer sometimes second guesses the author, I
> don't know if file extension plays a role in this.


Ok ok, it works now. Since all I did was changing the
extension without adding any code to it, I thought it
should have worked to same, but the file goes through php
anyway.

By the way, I forgot to say it but the problem was with
Mozilla Firebird, I just tried with Internet Explorer and
it worked even without the text/css header.

Thanks for the quick answer


--
SeeSchloß - http://www.seeschloss.net

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      09-30-2003
SeeSchloss wrote:

> By the way, I forgot to say it but the problem was with
> Mozilla Firebird, I just tried with Internet Explorer and
> it worked even without the text/css header.


Internet Explorer: This style sheet is written in text/html, bah I'll try to
treat it as CSS.

Firebird: This style sheet is written in text/html, I don't know how to
handle this, so I'll ignore it.

I much prefer Firebirds approach - if at some stage a different style sheet
language was created, that had similar syntax to CSS, IE would probably try
to treat it as CSS and get things very very wrong.

--
David Dorward http://dorward.me.uk/
 
Reply With Quote
 
brucie
Guest
Posts: n/a
 
      09-30-2003
In post <blcfm4$t6t$1$(E-Mail Removed)>
David Dorward said...

> <?php header('Content-type: text/css'); ?>
>
> [1] Internet Explorer sometimes second guesses the author, I don't know if
> file extension plays a role in this.


MIME Type Detection in Internet Explorer
http://msdn.microsoft.com/workshop/n...appendix_a.asp

--
01/October/2003 09:12:21 am
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
External stylesheets and custom controls BJF ASP .Net Building Controls 0 06-28-2004 12:38 AM
Re: user control stylesheets Michael Mckenzie ASP .Net 0 04-22-2004 10:06 PM
css in external stylesheets for aspx pages Rod Snyder ASP .Net 3 02-02-2004 04:01 PM
Changeing Stylesheets ADRIAN ASP .Net 0 11-05-2003 05:33 PM
Changing stylesheets Adrian ASP .Net 1 10-27-2003 04:49 PM



Advertisments