Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Nov 2005
    Posts
    27
    Member #
    11781
    I'm putting a site together at the moment which uses dynamically (via PHP) produced stylesheets. I've got it all working okay, but Firefox is bringing up a warning in the Javascript console saying that my stylesheets are of the wrong MIME type - that they're of type "text/html" rather than "text/css", which I'm specifying in the <link> tag.

    I'm not very knowledgeable when it comes to MIME types, so I don't know whether I need to be telling the browser to recognise PHP in this particular instance as being "text/css" or whether Apache/PHP is creating a "text/html" header to the file which I need to change.

    It's not a big problem but it's bugging me, so does anyone have a solution?

    Cheers
    Nick

  2.  

  3. #2
    Senior Member Fallout's Avatar
    Join Date
    Aug 2003
    Location
    Richmond, Virginia
    Posts
    543
    Member #
    2748
    Send a header through PHP like so:

    PHP Code:
    header('Content-type: text/css'); 
    Just be sure you put the header near the top of your code, because it will flag an error if there is something printed before it (or whitespace sometimes).

  4. #3
    Junior Member
    Join Date
    Nov 2005
    Posts
    27
    Member #
    11781
    Nice one. I knew it would be something simple like that but I couldn't find the command on PHP.net

    Do you know if the problem I had ever becomes a serious problem, e.g. with different browsers or funny security settings? The only difference I've found is that it's now easier to look at the dynamically produced CSS files becuase they're now displayed in Firefox like normal CSS

  5. #4
    Senior Member Fallout's Avatar
    Join Date
    Aug 2003
    Location
    Richmond, Virginia
    Posts
    543
    Member #
    2748
    I don't see why it would become a problem... because it should just dump the file's contents as CSS and not care about the extension or MIME type. Firefox was probably being overcautious.

  6. #5
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Better to be overly cautious than leave huge holes, a la the competition ;-)

    Seriously, it is kind of a problem, if you think about it.
    You're saying, "Open this file -- it's CSS," and the server says, "Here's the file, but dude, it's HTML, not CSS." Of course Firefox won't like that.

    It becomes even more important if you use PHP to dish up images (GIF or PNG generation, for example, or maybe a web-bug thing). The browser won't display an image with a text/html MIME type.
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:18 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com