PHP 中的 header_register_callback函

首页 / PHP入门教程 / PHP 中的 header_register_callback函

header_register_callback - 语法

bool header_register_callback ( callable $callback )

它将注册PHP开始发送输出时将调用的函数

Sr.No 参数 & Description
1

callback

它在发送标头之前调用。

header_register_callback - 返回值

成功时返回TRUE,失败时返回FALSE。

链接:https://www.learnfk.comhttps://www.learnfk.com/php/php-header-register-callback.html

来源:LearnFk无涯教程网

header_register_callback - 示例

<?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 "learnfk";
?>

这将产生以下输出-

learnfk

上面的示例将注册标头,并将回调标头作为文本,如上所述

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

微服务架构核心20讲 -〔杨波〕

快速上手Kotlin开发 -〔张涛〕

从0开发一款iOS App -〔朱德权〕

高并发系统设计40问 -〔唐扬〕

To B市场品牌实战课 -〔曹林〕

容器实战高手课 -〔李程远〕

陈天 · Rust 编程第一课 -〔陈天〕

Go进阶 · 分布式爬虫实战 -〔郑建勋〕

结构执行力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)