Re: do i need to output headers on parsed CSS files?

From: Date: Thu, 24 Jul 2003 03:18:38 +0000
Subject: Re: do i need to output headers on parsed CSS files?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-156581@lists.php.net to get a copy of this message
* Thus wrote Justin French (justin@indent.com.au): > Hi all, > > I'm forcing my style sheets (.css) though the PHP parser, so that they > can take advantage of some color variables and global config settings > via include files, eg: > > body { > background-color: #<?=$col['1']?>; > } > > however, I've noticed that when viewing the CSS file in a browser now, > it looks more like a HTML document int he browser (variable width > fonts, no newlines, etc) rather than other css files (wich look like > they have <pre> tags aroun them (newlines visible, fixed-width font, > etc). That is IE (or your browser) doing that, because it saw a header text/html. > > So, my assumption is that pushing the .css file through PHP is putting > the wrong header on the file (text/html) rather than text/css -- or > perhaps something else -- my header knowledge is poor. Yes php by default will send out text/html. > > Anyway, the pages and linked CSS files *work* but do not validate any > more, witha warning "You can't import an HTML document". > > > What/how should I force the correct headers on these PHP-parsed CSS > files? header('Content-Type: text/css'); On a side note, You should also make your css get cached by the browser otherwise it sort of defeats one of the purposes of having the style seperate from the html (the broswer doesn't have to request it all the time). So what I would do would is add a Last-Modified header. Usually I stat() $PHP_SELF (if possible) and get the last modified then translate the unix timestamp to: header('last-modified: ' . date('U', $ts_of_php_self)); This way the browser should at least keep it in the cache for the session. HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#156581) next »