Network header_register_callback

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

header_register_callback — 헤더 함수 호출


설명

header_register_callback(callable $callback): bool

PHP가 출력을 보내기 시작할 때 호출될 함수를 등록합니다.

callback은 PHP가 보낼 모든 헤더를 준비한 직후에 실행되고 다른 출력이 전송되기 전에 전송되기 전에 나가는 헤더를 조작하는 창을 만듭니다.


매개변수

callback
헤더가 전송되기 직전에 호출되는 함수입니다. 매개변수를 가져오지 않으며 반환 값은 무시됩니다.

반환 값

성공하면 true를, 실패하면 false를 반환합니다.


Examples

예제 #1 header_register_callback() 예제

                  
<?php

header('Content-Type: text/plain');
header('X-Test: foo');

function foo() {
 foreach (headers_list() as $header) {
   if (strpos($header, 'X-Powered-By:') !== false) {
     header_remove('X-Powered-By');
   }
   header_remove('X-Test');
 }
}

$result = header_register_callback('foo');
echo "a";
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

Content-Type: text/plain

a
                

메모

header_register_callback()은 헤더가 전송되려고 할 때 실행되므로 이 함수의 출력은 출력을 중단할 수 있습니다.

메모: 헤더를 지원하는 SAPI가 사용 중일 때만 헤더에 액세스하고 출력할 수 있습니다.


기타

  • headers_list() - 보낸(또는 보낼 준비가 된) 응답 헤더 목록을 반환합니다.
  • header_remove() - 이전에 설정한 헤더 제거
  • header() - 원시 HTTP 헤더 보내기