Page 1 of 1

Output_Buffering outputs buffer content twice?

Posted: Sat Jan 21, 2006 5:04 pm
by protegechris
First experience using output buffering on my own and I'm having some problems.

Here's the basic layout:

Code: Select all

<?php

if (!defined("IN_MKP")) {
   die ("Sorry !! You cannot access this file directly.");
}
ob_start();
?>
..CLIPPED ENDLESS CODE..

<?
ob_end_flush();
$output = ob_get_contents();
$mklib->printpage("1", "1", "Playlist and Requests", $output);
?>
It works fine, it prints the contents in the content area, but it includes it before it prints the page, including it on the page twice. What'd I do wrong? It includes it at the top of the page whether I include end_flush or not.. any advice?

Posted: Sat Jan 21, 2006 5:11 pm
by shiznatix
so are you echoing out the ouput once then letting the page output it as usual? if you echo it then the browser echos it then it will be shown twice.

Posted: Sat Jan 21, 2006 5:27 pm
by protegechris
Not sure what I'm doing, first time with ob, I'm more of a PHP-MySQL guy ;)

I have tried using:

Code: Select all

<?
$output = ob_get_contents();
$mklib->printpage("1", "1", "Playlist and Requests", $output);
?>
Leaving out the flush, but that does the same thing.. Declaring $output as ob_end_flush outputs the "REMOVED ENDLESS CODE" line above the printed page, and outputs a "1" in place of the $output area. I'm basically trying to include a heavy PHP page into a CMS, which unlike something like PHPNuke doesn't give me the option of using Open and CloseTable functions, I was told output buffering would be my best bet.

Even if I completely remove the $output declaration and never even end the buffer, it still displays the code above the page :?

Posted: Sat Jan 21, 2006 6:23 pm
by feyd

Posted: Sat Jan 21, 2006 7:45 pm
by protegechris
Thanks Feyd, just right. I had been looking for a good PHP forum, found it :) Thanks for the help guys, you just made the rest of my weekend a whole lot easier :)