Jump to content

Stopping output??


Tandem

Recommended Posts

Is there a way to stop things that you've already told php to output from actually being output?

For example if i needed to echo something out before a form validation process, but under certain results of the validation i no longer want that to be echoed at the beginning, is there a way of making it not be echoed? Sort of like making your script not echo things that you have already told php to echo further up the script.

Sorry if that makes no sense but i'm having trouble finding explaining it properly.

Thanks in advance for any replies.
Link to comment
Share on other sites

Sorry, it's not as simple as that.

The original echo needs to be done before the validation begins, but if the validation is successful then i include a different page (can't use headers in this instance) and exit the script before anything else but the text is output, but then i am left with an obscure output at the top of the included page. I'm asking if there is any sort of function or way that stops anything that has already been told to output, from actually being output so that i'm not left with the obscure message at the top of the included page.
Link to comment
Share on other sites

How about using an iframe to display your messages? This is a pretty basic example, but you could have your original echo in a "shell" and load the appropriate pages into the iframe depending on the validation results.

[code=php:0]echo 'Original echo';
// start validation
if($validation == 'true') {
echo '<iframe name="foo" src="page1.php">';
die();
} else {
echo '<iframe name="bar" src="page2.php">';
die();
}[/code]

Or you could redirect
[code=php:0]echo 'Original echo';
// start validation
if($validation == 'true') {
echo '<meta http-equiv="refresh" content="0;url="page1.php">';
die();
} else {
echo '<meta http-equiv="refresh" content="0;url="page2.php">';
die();
}[/code]
Link to comment
Share on other sites

The problem with that is that i echo some other messages to go at the top of the included page if the validation is successful.

I don't think it is possible for me to keep the message due to the structure of my script, was just asking on the off chance that there was a magic function that would solve my problems :P

Thanks for the replies.
Link to comment
Share on other sites

[quote author=Tandem link=topic=124073.msg513654#msg513654 date=1169771979]
The problem with that is that i echo some other messages to go at the top of the included page if the validation is successful.

I don't think it is possible for me to keep the message due to the structure of my script, was just asking on the off chance that there was a magic function that would solve my problems :P

Thanks for the replies.
[/quote]

you may get some use out of [url=http://php.net/exit]exit()[/url]. you may not =\
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.