Home > Backend Development > PHP Tutorial > 判断是否有 header("Content-type: text/html; charset=utf-8");该如何处理

判断是否有 header("Content-type: text/html; charset=utf-8");该如何处理

WBOY
Release: 2016-06-13 12:22:41
Original
2465 people have browsed it

判断是否有 header("Content-type: text/html; charset=utf-8");
如何判断是否有 header("Content-type: text/html; charset=utf-8");
有时如果前面已经有这代码,再加上这代码就出错,如何判断
因为这文件是用include 调用的,很多页面都调用这文件,这文件中有 header("Content-type: text/html; charset=utf-8");
------解决思路----------------------
headers_sent 返回假时,表示没有 http 头发出

headers_list() 取得所有发出的头内容

header_remove 删除指定的头
------解决思路----------------------

引用:
如何判断是否有 header("Content-type: text/html; charset=utf-8");
有时如果前面已经有这代码,再加上这代码就出错,如何判断
因为这文件是用include 调用的,很多页面都调用这文件,这文件中有 header("Content-type: text/html; charset=utf-8");


这样试试
<br />header("Content-type: text/html; charset=utf-8");<br /><br />addHeader();<br /><br />function addHeader(){<br />    $header = 'Content-type: text/html; charset=utf-8';<br />    if(!in_array($header, headers_list())){<br />        header($header);<br />    }<br />}<br />
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template