Output Buffer Problem?

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
lzhengqc
Forum Newbie
Posts: 3
Joined: Mon Mar 26, 2007 8:24 am

Output Buffer Problem?

Post by lzhengqc »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


thanks for anyone who can help on this. I am sure that someone out there get to be smarter than me. 
I got a parse error from a php generated php file.

Here is the php file to generate php code.

Code: Select all

ob_start();
// Php Code
// Printing to the output buffer
$phpCode = ob_get_contents();
ob_end_clean();

$cacheCode=""; \\ some cache code

$phpCode = "<?php ob_start(); ?>". $cacheCode . $phpCode;
$phpCode .= "\n";
$phpCode .= "<!-- <?= \$_ENV['HOSTNAME'] ?> -->\n";
$phpCode .= "<?php ob_flush(); ?>";
It generated following parse error after first <?php ob_flush(); ?>. it starts some crazy code that I have no idea where it comes from.

Code: Select all

<script>
function changeDiv()
<?php
	if ($showWidthAlerts) {
?>
			alert("Page Width: " + pageWidth);
			alert("Column Id: 1070616 = " + getElement("resizeColumn1070616").style.width);
			if (minReached == 1) {
				alert("Min - Column Id: 1070616 = " + getElement("resizeColumn1070616").style.width);
			}
			if (maxReached == 1) {
				alert("Max - Column Id: 1070616 = " + getElement("resizeColumn1070616").style.width);
			}
	
<?php
				} // END if - show width alerts
	?>
					} // END function - changeDiv
window.onresize=new Function("changeDiv()");
// -->
</script>
</body>
</html>
<?php
include_once "globalconsts.lib";
include_once "globaldb.lib";
?>

<!-- <?= $_ENV['HOSTNAME'] ?> -->
<?php ob_flush(); ?>ched == 1) {
						alert("Max - Column Id: 1070616 = " + getElement("resizeColumn1070616").style.width);
					}
<?php
				} // END if - show width alerts	
				?>
						} // END function - changeDiv
		window.onresize=new Function("changeDiv()");
	// -->
</script>
</body>
</html>
<?php
include_once "globalconsts.lib";
include_once "globaldb.lib";
?>
<!-- <?= $_ENV['HOSTNAME'] ?> -->
<?php ob_flush(); ?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Where did you get this code from? I assume its storing stuff in the database then executing it.

My advice is to ditch this code and use something of your own as the little you posted looks like trouble now and even more trouble later.
lzhengqc
Forum Newbie
Posts: 3
Joined: Mon Mar 26, 2007 8:24 am

Thanks for looking over the code

Post by lzhengqc »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thanks for looking over the code. But get ride of code is something I can not do. It is the main source of the code that we used to create more than 100,000 pages each day. It always working fine. Until I recently added few more javascript and php code to the output buffer section.  I am still looking for answers to see if anyone had this problem before and what is the solution. 

does anyone every see php Output something like this before?

[syntax="html"]<script>
if(alert)
{
    alert("this is a alert statement");
}else
{
    alert("Don't alert anything");
}
</script>t("this is a alert statement");
}else
{
    alert("Don't alert anything");
}</script>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Could be related to this little beauty...

<?php ob_flush(); ?>ched == 1)

What is that supposed to do for you?
lzhengqc
Forum Newbie
Posts: 3
Joined: Mon Mar 26, 2007 8:24 am

Thanks Everah - but it did not solve my problem

Post by lzhengqc »

Thanks for the comment Everah. <?php ob_flush(); ?>ched == 1) is generated by php code.

My php code generated all the way to <?php ob_flush(); ?>

some how something else is adding "ched == 1) " and other code behind it. I am still trying to figure out where it is generated. but I have no more php code after <?php ob_flush(); ?>

Still looking for someone had this problem.

example:
php code
<php?
ob_start();
print("This is first line.<br>");

print("this is second line.<br>");
ob_flush();
?>

OUTPUT:
This is first line.
This is second line.irst line
This is second line.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Something is messed up. Its like appears there are nested ob_cache() statements and its like reechoing everything but only getting half of it. I don't even know where to start troubleshooting that, its a real mess.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I highly doubt this will work, but just for giggles, can you use string literals instead of parsed strings...

Change:

Code: Select all

<?php
$phpCode = "<?php ob_start(); ?>". $cacheCode . $phpCode;
$phpCode .= "\n";
$phpCode .= "<!-- <?= \$_ENV['HOSTNAME'] ?> -->\n";
$phpCode .= "<?php ob_flush(); ?>";
?>
To:

Code: Select all

<?php
$phpCode = '<?php ob_start(); ?>'. $cacheCode . $phpCode . "\n";
$phpCode .= '<!-- <?= $_ENV[\'HOSTNAME\'] ?> -->' . "\n";
$phpCode .= '<?php ob_flush(); ?>';
?>
Again, I highly doubt this is the problem, but I want to make sure.
Post Reply