headers_list

(PHP 5)

headers_list -- 返回已傳送(或準備傳送)的響應標頭的清單

說明

array headers_list ( void )

headers_list() 將返回一個數字索引的陣列,包括有向瀏覽器/用戶端傳送的標頭。要判斷標頭是否已被傳送,使用 headers_sent()

例子 1. headers_list() 例子

<?php

/* setcookie() will add a response header on its own */
setcookie('foo''bar');

/* Define a custom response header
   This will be ignored by most clients */
header("X-Sample-Test: foo");

/* Specify plain text content in our response */
header('Content-type: text/plain');

/* What headers are going to be sent? */
var_dump(headers_list());

?>

上例的輸出類似於:

array(4) {
  [0]=>
  string(29) "X-Powered-By: PHP/5.0.0"
  [1]=>
  string(19) "Set-Cookie: foo=bar"
  [2]=>
  string(18) "X-Sample-Test: foo"
  [3]=>
  string(24) "Content-type: text/plain"
}

參見 headers_sent()header()setcookie()