• PHP Video Tutorials

PHP - Function Header Register Callback



Syntax

bool header_register_callback ( callable $callback )

Definition and Usage

It will register the function that will be called when PHP start sending output

Return Values

It returns true on success and false on failure.

Parameters

Sr.No Parameters & Description
1

callback

It called before the headers are sent.

Example

Try out following example

<?php
   header('Content-Type: text/plain');
   header('X-Test: f1');
   
   function f1() {
      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('f1');
   
   echo "tutorialspoint";
?>

This will produce following result −

tutorialspoint

The above example will register the header and it will callback the header as a text as shown above

php_function_reference.htm
Advertisements