2

So I have this bit of code:

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));
                }
            }
        }

For the life of me I cant figure out why everything in the error log is blank (it gets all the way to the last else statement where I am printing variables). Even the headers return nothing. This function is called with static parameters EVERYWHERE it is included. There is a 0% chance of this function being called without $html or $section having some value. HELP!!!!

-PS the page that this is being called from works fine when I try it.

Edit:To be a little more precise here, What it looks like its doing is NOT starting the buffer, including the file, and then dumping the contents of the buffer. Is there some way PHP will turn off the buffers on occasion if there are no headers of if the user disconnected already or something?

Nimrod5000
  • 130
  • 8
  • Post the error log function to figure out why – mertizci Mar 04 '16 at 23:56
  • There is no error in the normal log. I set this up to catch it instead. – Nimrod5000 Mar 06 '16 at 03:12
  • No output (or a blank page, or a "500 Internal Server Error" status code) normally means that your script is throwing an error but you haven't configured PHP to display error messages. Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). – Álvaro González Mar 07 '16 at 17:04
  • Well the issue is that it finds the file and then for some reason the output buffer is returning blank. These lines seem to be the culprit even though the include path is absolutely correct:ob_start(); include GLOBAL_DIR.'/assets/inc/pages/'.$html; //$string = ob_get_clean(); $string = ob_get_contents(); – Nimrod5000 Mar 07 '16 at 17:31

0 Answers0