Output_Buffering outputs buffer content twice?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
protegechris
Forum Newbie
Posts: 3
Joined: Sat Jan 21, 2006 4:59 pm

Output_Buffering outputs buffer content twice?

Post 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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
protegechris
Forum Newbie
Posts: 3
Joined: Sat Jan 21, 2006 4:59 pm

Post 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 :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

protegechris
Forum Newbie
Posts: 3
Joined: Sat Jan 21, 2006 4:59 pm

Post 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 :)
Post Reply