header_register_callback

(PHP 5 >= 5.4.0, PHP 7)

header_register_callback����һ�� header ����

˵��

header_register_callback ( callable $callback ) : bool

ע��һ���������� PHP ��ʼ�������ʱ���á�

PHP ׼����������Ӧͷ���ڷ�������֮ǰִ�� callback��������һ��������Ӧͷ�IJ������ڡ�

����

callback

��ͷ����ǰ���ú����� ��û�в��������ص�ֵҲ�ᱻ���ԡ�

����ֵ

�ɹ�ʱ���� TRUE�� ������ʧ��ʱ���� FALSE��

����

Example #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() ����ͷ��������ǰִ�еģ� ���Ա������������������������������̡�

Note:

����ͷֻ����SAPI֧��ʱ�õ�����������

�μ�

  • headers_list() - �����ѷ��͵� HTTP ��Ӧͷ����׼�����͵ģ�
  • header_remove() - ɾ��֮ǰ���õ� HTTP ͷ
  • header() - ����ԭ�� HTTP ͷ