[英]Get current Content-Type header in PHP
我正在运行一个PHP脚本来记录MySQL数据库中对我站点的所有请求。 我网站上的一些脚本也使用header("Content-Type: image/png");
修改Content-Type
header("Content-Type: image/png");
例如,输出图像。 我也试图记录这个Content-Type。 如何获取包含Content-Type的字符串变量?
你的脚本是什么样的? 什么时候执行? 如果它在每个脚本的末尾执行,您可以使用php function headers-list检查当前设置的标题
这是一个如何使用它的简单示例:
<?php
// headers sent
$headers = headers_list(); // get list of headers
foreach ($headers as $header) { // iterate over that list of headers
if(stripos($header,'Content-Type') !== FALSE) { // if the current header hasthe String "Content-Type" in it
$headerParts = explode(':',$header); // split the string, getting an array
$headerValue = trim($headerParts[1]); // take second part as value
$yourLoggingService->setContentTypeOfCurrentCall($headerValue);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.