Forum Moderators: coopster

Message Too Old, No Replies

I'm told I have to use php.ini instead of .htaccess

trying to get php to parse other file extensions

         

benlieb

5:39 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



My host told me that the directive:

AddType application/x-httpd-php .css

can't be used because of the way suphp is set up and that I have to use a php.ini file. However, after hours of searching, I can't find the syntax required to create this php.ini file, and to get it to parse other extensions such as .html .css .foo .etc

Anyone have exerience with this & can show me the syntax?

ergophobe

6:16 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't think your host knows what he's talking about (then again, I might be confusing him with myself!).

Seriously, the php.ini file is only going to get invoked if the PHP parser is invoked, so it's too late in the stream to do anything about telling Apache how to handle files with a .css extension. Those directives must be set in either the httpd.conf file (Apache settings) or the .htaccess file.

Tom

jetboy_70

6:25 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



Yep, ergophobe's right. httpd.conf if you have root access to your Apache install - highly unlikely if you're in a shared hosting environment - or .htaccess if you don't (or choose not to use httpd.conf). The syntax is the same as you already have in either file.

benlieb

7:06 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



I have tried the .htaccess method (see orig post) and it won't work. On contacting my host, they said I must use a php.ini file. But now I see that this is a circular solution (i.e. no solution at all). Unless of course when the apache server boots it flags those extensins to php so that it is listening even though it is not parsing. Or something like that. I don't know.

What other options are there? I will send off an email to the "high level" tech guys there and see...

StupidScript

7:25 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



.htaccess files are used by an Apache web server. If your host is using MS IIS or something other than Apache, you'll need to see if there is an .htaccess alternative available.

Could you post the contents of your .htaccess file, just in case your running Apache but have a ding in your code? :)

StupidScript

7:41 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And another thing ...!

Why are you attempting to parse a .CSS file through PHP?

If you need custom style settings based on PHP variables, you should use the PHP to load a specific .CSS file or to make modifications to style instructions after the primary .CSS file has loaded through a combination of Javascript and the PHP variables.

I know it seems like writing a remote .CSS file using PHP and the including it normally might work, but .CSS files and PHP files have different header data which is messing with you. The server is already instructed in how to post files with a .CSS extension (text/css), so changing those headers by writing the file with PHP probably breaks one or the other.

jetboy_70

8:30 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



StupidScript, although it may not seem immediately obvious why you'd want to do it, it does in fact work quite well. The only caveat is that you have to use PHP to put a text/css header at the top of each CSS file, otherwise it falls over in Mozilla 0.9 and later.

The often overlooked issue is that PHP enabling CSS files prevents them being cached by the browser, which is half the point of external CSS in the first place! However, if you're prepared to split your CSS into static and dynamic files, with appropriate folder level .htaccess files, it shouldn't be a problem.

StupidScript

8:50 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP enabling CSS files prevents them being cached by the browser

How so? The page is compiled and delivered the same as a non-compiled page, i.e.:

<link rel="stylesheet" type="text/css" href="style.css">

ends up on the page and makes the request regardless of whether the page was compiled or not, doesn't it?

Thanks.

jetboy_70

10:35 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



With a regular CSS file:

HTTP/1.0·200·OK(CR)
(LF)
Date:·Fri,·12·Nov·2004·22:28:57·GMT(CR)
(LF)
Server:·Apache/1.3.27·(Unix) ... PHP/4.3.2 ... (CR)
(LF)
Last-Modified:·Thu,·28·Oct·2004·23:11:27·GMT(CR)
(LF)
ETag:·"36412c-b6a-41817c9f"(CR)
(LF)
Accept-Ranges:·bytes(CR)
(LF)
Content-Length:·2922(CR)
(LF)
Connection:·close(CR)
(LF)
Content-Type:·text/css(CR)

With a PHP parsed CSS file (with a text/css header):

HTTP/1.1·200·OK(CR)
(LF)
Date:·Fri,·12·Nov·2004·22:27:01·GMT(CR)
(LF)
Server:·Apache/1.3.27·(Unix) ... PHP/4.3.2 ... (CR)
(LF)
X-Powered-By:·PHP/4.3.2(CR)
(LF)
Connection:·close(CR)
(LF)
Content-Type:·text/css(CR)

I'd imagine that the lack of Content-Length and Last-Modified headers would be the critical differences.

StupidScript

12:41 am on Nov 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Veddy interesting. Thanks, jetboy!

StupidScript

6:11 pm on Nov 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the same true for .JS pages compiled by PHP?

(I'm simply too lazy to test it, myself. :)

benlieb

5:37 am on Nov 16, 2004 (gmt 0)

10+ Year Member



in case anyone still cares, I have solved the mystery. Well the elite support technician solved it. I was told to put

AddType x-httpd-php .css

instead of:

AddType application/x-httpd-php .css

Couldn't tell you why this works. I'm not an apache guru. Now to worry about/understand the caching issue...