jggretton Posted March 28, 2011 Share Posted March 28, 2011 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{ .......... Quote Link to comment https://forums.phpfreaks.com/topic/231932-headers-sporadically-being-outputted-as-text-in-php-driven-css-document/ Share on other sites More sharing options...
jggretton Posted March 29, 2011 Author Share Posted March 29, 2011 Hmmm, has no-one experienced anything like this before then? I'm really stuck so would appreciate any ideas, however vague they might be! Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/231932-headers-sporadically-being-outputted-as-text-in-php-driven-css-document/#findComment-1193629 Share on other sites More sharing options...
jggretton Posted March 31, 2011 Author Share Posted March 31, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/231932-headers-sporadically-being-outputted-as-text-in-php-driven-css-document/#findComment-1195104 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2011 Share Posted March 31, 2011 Please post the PHP code between tags that's causing the problem. Without seeing your code, we really can't help you. Ken Quote Link to comment https://forums.phpfreaks.com/topic/231932-headers-sporadically-being-outputted-as-text-in-php-driven-css-document/#findComment-1195106 Share on other sites More sharing options...
jggretton Posted March 31, 2011 Author Share Posted March 31, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/231932-headers-sporadically-being-outputted-as-text-in-php-driven-css-document/#findComment-1195135 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2011 Share Posted March 31, 2011 What happens when you put non CSS code in a CSS file and bring it into you HTML? Ken Quote Link to comment https://forums.phpfreaks.com/topic/231932-headers-sporadically-being-outputted-as-text-in-php-driven-css-document/#findComment-1195150 Share on other sites More sharing options...
jggretton Posted March 31, 2011 Author Share Posted March 31, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/231932-headers-sporadically-being-outputted-as-text-in-php-driven-css-document/#findComment-1195198 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.