Jump to content

Headers sporadically being outputted as text in php driven css document.


jggretton

Recommended Posts

Hi all, I've got a frustrating problem on a site where PHP is outputting content *before* the headers, causing the headers to show up as plain text.

 

This is only happening on a .css file which is powered by PHP (at least I'm only noticing it on a .css file) and is only happening occasionally, usually the second time I visit the site in a session, and not again for a while. Pressing refresh fixes it.

 

I've listed some of the output below, lots of unknown chars, followed by the headers and then finally the actual stylesheet. Not that the first part may not have copy and pasted 100% accurately.

 

If anyone has any ideas I'd be very grateful.

 

Thanks,

 

James

 

 

��#��P��(vԄ��l�?ml��ʇD�n.��r�����N
d�F1eO�L4�� (Cc0��4�%s��h/�W�����zZ�y��%�`�����M“�c^^�I3s�8���#����]A���R��Hȗ��`G{�
HTTP/1.1 200 OK
Date: Mon, 28 Mar 2011 08:24:46 GMT
Server: Apache/2.2.17 (Unix) FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.17
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/css

24d8

@charset "utf-8";

/*---Stylesheet---*/

html, body{
..........

Link to comment
Share on other sites

Well, I still don't know what's actually going wrong, but I've narrowed down the problem to DEFLATE compression in my .htaccess file.

 

The problem is being caused by the following .htaccess rule:

 

AddOutputFilterByType DEFLATE text/html

 

If I remove this line then all works fine. Gzip isn't really essential for this site so I'm happy to leave it this way.

 

Hopefully this will help anyone else with the same problem.

 

If anyone does know what's really causing the problems here please do reply anyway - I'd be very interested to know.

 

Many thanks,

 

James

Link to comment
Share on other sites

Hi Ken, I hadn't posted code previously as there was a lot of framework stuff going on too, but after some experimentation I've managed to get the problem to occur with nothing but this code:

 

/css.php

<?
header("Content-Type: text/css"); 
print "test";
?>

 

/.htaccess

AddOutputFilterByType DEFLATE text/html text/plain application/json

 

A few other points:

  • So far, I've only noticed it in Google Chrome on the PC (XP & Windows 7) but this might be because the other browsers are more forgiving of fluff at the top of a css file
  • It doesn't occur when accessing a file directly, only when it's loaded in by my HTML (so perhaps related to Connection: keep-alive?)
  • When it does occur, the file comes down with no response headers. Chrome is then treating it as a application/octet-stream

 

 

Link to comment
Share on other sites

So far, from what I can tell if it's a standard .css file it comes through fine, if it's a php driven one it occasionally goes wrong.

 

I've actually founds another quirk which is that it seem to make a difference what html file (well, php file) I load the css document through. I'm not at my work station anymore, but I'll look into this further tomorrow, but it might be something to do with if the html file is still loading when it loads in the css... Not sure if that's right, but it's an idea.

 

Thanks for your help, James

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.