内容类型没有在PHP工作 [英] Content-type not working in PHP

查看:105
本文介绍了内容类型没有在PHP工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那工作不正常的PHP文件的一些问题。内容类型不会获得任何浏览器都收到。萤火虫间$ P $点文件为text / html,而不是CSS。这里的文件:

I have some issues with a PHP file that is not working properly. The Content-type does not get recieved by any browser at all. Firebug interprets the file as text/html instead of css. Here's the file :

<?php
header('Content-Type: text/css; charset=UTF-8');
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
/* CSS goes on from here */

我测试过把一排回声TEST; 头前行,并期待看到错误的经典已经发送了头,但似乎没有什么!

I tested to put a row with echo 'TEST'; before the header line, and was expecting to see the classic "headers already sent" error, but nothing appears!

普通的CSS-文件正在像然而,一个魅力。

Normal .css-files are working like a charm however.

我能做些什么来排序了这一点?

What can I do to sort this out?

更新:
确实改变 default_mimetype =text / html的来在php.ini default_mimetype =文/ CSS和所有页面有PTED为CSS立即间$ p $,所以有一定的方式只是给CSS标头文件:)

UPDATE: Did change default_mimetype = "text/html" to default_mimetype = "text/css" in php.ini and all pages got immediately interpreted as css, so there's must be a way to just send css headers for this file :)

从约翰需求的完整文件:

The full file from demand of John:

    <?php
    header('Content-Type: text/css; charset=UTF-8');
    echo 'body {background-color: #000000; }';
    ?>

更新#2:
添加的ini_set('default_mimetype','文/ CSS'); 到PHP文件修复了这个文件,但它并没有解决导致此故障的问题...

UPDATE #2: Adding ini_set('default_mimetype', 'text/css'); to the PHP file fixes this file, but it doesn't solve the issue that causes this fault...

更新3:
经测试加入将AddType文字/ CSS的.css 双方的.htaccess和Apache的配置。仍然没有运气。还测试发送字符集,从分离标题:头('内容类型:text / CSS'); - 仍然没有运气...

UPDATE #3: Tested adding AddType text/css .css to both .htaccess and Apache config. Still no luck. Also tested to send headers separated from charset: header('Content-Type: text/css'); - Still no luck...

更新#4:
重新安装的Apache + PHP的服务器,看看问题是否会消失,但没有。同样的老样子...

UPDATE #4: Have reinstalled Apache+PHP at the server to see if the problem goes away, but no. Same old, same old...

推荐答案

检查您的php.ini文件的output_buffering设置。如果它没有设置为关比PHP自动做输出缓冲你。设置为关闭,呼应标题命令之前的东西,你应该看到经典错误。

Check your php.ini file for the output_buffering setting. If it's not set to "off" than PHP is automatically doing output buffering for you. Set that to off and echo something before the header command, and you should see the "classic error".

您不应该使用结束?>。我知道这是一个有争议的建议,但次数过多的人加入后,返回和/或空间,获取输出到浏览器(前标题)。还有它不使用它会导致问题极少数情况下。

You shouldn't use the closing ?>. I know this is a controversial suggestion, but too many times people add a return and/or space after it, which gets output to the browser (before the header). There are very few cases where it not using it would cause a problem.

这篇关于内容类型没有在PHP工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆