getallheaders()返回一个空白

时间:2016-03-04 23:02:40

标签: php header request-headers

所以我有这段代码:

function global_include($html,$section){
            if (!isset($html)) { //Need to write better error checking
                error_log('Global Include Error: '.iam().' '.$_SERVER['PHP_SELF'].' - '.$html.'-'.$section,0); // WRITE TO LOG
                echo '<p>Error fetching data</p>';
            }else {
                ob_start();
                include GLOBAL_DIR.'/assets/inc/pages/'.$html;
                //$string = ob_get_clean();
                $string = ob_get_contents();
                ob_end_clean();
                $htmlobj = str_get_html($string);
                if(is_object($htmlobj)){//check for returned html to be a properly formed and parsed xml object
                    $el = $htmlobj->find($section, 0);
                    $innertext = $el->innertext;
                    echo $innertext;
                }else{
                    error_log('(User tried to access invalid html object with global_include() at ' . GLOBAL_DIR . '/assets/inc/pages/' . $html . ') ' . 'Request URI: ' . $_SERVER['REQUEST_URI'] . ' - HTTP Referer: ' . $_SERVER['HTTP_REFERER'] . ' - User Agent: ' . $_SERVER['HTTP_USER_AGENT'] . ' - IP Address: ' . $_SERVER['REMOTE_ADDR'] . ' HTML ASKED: ' . $html . ' SECTION ASKED: ' . $section . ' SECTION RETURNED: ' . $string . ' HTMLOBJ: ' . print_r($htmlobj, true) . ' HEADERS: ' . print_r(getallheaders(), true));
                }
            }
        }

对于我的生活,我无法弄清楚为什么错误日志中的所有内容都是空白的(它会一直到我打印变量的最后一个else语句)。即使标题也没有返回。使用静态参数调用此函数,其中包含它。在没有$ html或$ section的情况下调用此函数的可能性为0%。帮助!

-PS我正在尝试调用它的页面工作正常。

编辑:要在这里更精确一点,它看起来的样子不是启动缓冲区,包括文件,然后转储缓冲区的内容。有没有什么方法如果用户已经断开连接或者什么东西没有标题,PHP有时会关闭缓冲区?

0 个答案:

没有答案