从 Lighttpd 响应中删除 Content-Type header
Remove Content-Type header from Lighttpd response
我写了一个函数叫 IO::stdout:
class IO {
public static function stdout($var) {
$stdout = fopen('php://stdout', 'w');
fwrite($stdout, $var, strlen($var));
fclose($stdout);
}
}
IO::stdout("Hello World!");
好吧,它有效!但是当我请求页面时,它显示我:
Hello World!
X-Powered-By: PHP/5.6.13
Content-type: text/html; charset=UTF-8
在 php.ini 中设置 expose_php = Off
删除了 X-Powered-By header,但仍然打印 Content-Type header。它可能是由 Lighttpd 添加的。如何禁用 Content-Type header?
这是默认值 PHP header: http://php.net/manual/fr/ini.core.php#ini.default-mimetype
您不能使用 header_remove
删除它,因为缺少 Content-Type
header 将触发默认 mime-type.
相反,尝试将其设置为空字符串:
header('Content-Type:', true);
true
将删除之前任何类似的 header.
郑重声明,header 的名字不区分大小写,并且 PHP 以发送带有小 t
的 Content-type
为人所知。
也可以发右边的Content-Type
(我觉得应该是text/plain
)
我写了一个函数叫 IO::stdout:
class IO {
public static function stdout($var) {
$stdout = fopen('php://stdout', 'w');
fwrite($stdout, $var, strlen($var));
fclose($stdout);
}
}
IO::stdout("Hello World!");
好吧,它有效!但是当我请求页面时,它显示我:
Hello World!
X-Powered-By: PHP/5.6.13
Content-type: text/html; charset=UTF-8
在 php.ini 中设置 expose_php = Off
删除了 X-Powered-By header,但仍然打印 Content-Type header。它可能是由 Lighttpd 添加的。如何禁用 Content-Type header?
这是默认值 PHP header: http://php.net/manual/fr/ini.core.php#ini.default-mimetype
您不能使用 header_remove
删除它,因为缺少 Content-Type
header 将触发默认 mime-type.
相反,尝试将其设置为空字符串:
header('Content-Type:', true);
true
将删除之前任何类似的 header.
郑重声明,header 的名字不区分大小写,并且 PHP 以发送带有小 t
的 Content-type
为人所知。
也可以发右边的Content-Type
(我觉得应该是text/plain
)