sien6

PHP 判断Header 送出前, 是否有值被送出去: headers_sent()

1 为避免header()函数是,出现

<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /var/www/test.php:5) in <b>/var/www/test.php</b> on line <b>6</b><br />

错误,我们可以在进行header()导向跳转时,使用:

if (!headers_sent()) {

    header(\'Location: b.php\');

    exit;

}

进行判断调用header之前是否有文件输出。

 

2 也可以用来呈现准备输出的header数据,使用header_list()进行查看。

<?php

setcookie(\'abc\', \'test\');

header(\'Content-type: text/plain\');


// headers_list() 会输出数组结构的数据信息
print_r(headers_list());

 

 

参考网址:http://blog.163.com/bhao_home/blog/static/66477631201592021818384/

发表于 2017-06-12 10:25  逝火  阅读(131)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章: