Clear previously set headers php

前端 未结 4 914
忘掉有多难
忘掉有多难 2021-02-05 16:15

I would like to know if its possible to clear the current information stored in header_list()

if(headers_sent()){
    foreach(headers_list() as $header){
                


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 16:38

    headers_sent indicates that it is too late to remove headers. They're already sent. Hence the name of the function.

    What you want is to specifically check if the headers have not been sent yet. Then you know it's safe to modify them.

    if (!headers_sent()) {
      foreach (headers_list() as $header)
        header_remove($header);
    }
    

提交回复
热议问题