[英]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.