Tandem Posted January 25, 2007 Share Posted January 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/35746-stopping-output/ Share on other sites More sharing options...
tgavin Posted January 26, 2007 Share Posted January 26, 2007 [code=php:0]// beginning of scriptif($validation = 'true') { echo $results;}// do other stuffif($validation != 'true') { echo $results;}// remainder of script[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35746-stopping-output/#findComment-169407 Share on other sites More sharing options...
Tandem Posted January 26, 2007 Author Share Posted January 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/35746-stopping-output/#findComment-169412 Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 Stop echoing it in the first place. This indicates a structural issue. Quote Link to comment https://forums.phpfreaks.com/topic/35746-stopping-output/#findComment-169414 Share on other sites More sharing options...
Tandem Posted January 26, 2007 Author Share Posted January 26, 2007 Yeah i can do that, it's just it is a useful indicator and was wondering if there was any way for it to be saved rather than having to scrap it. I guess not though.Thanks for the replies. Quote Link to comment https://forums.phpfreaks.com/topic/35746-stopping-output/#findComment-169415 Share on other sites More sharing options...
tgavin Posted January 26, 2007 Share Posted January 26, 2007 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 validationif($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 validationif($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] Quote Link to comment https://forums.phpfreaks.com/topic/35746-stopping-output/#findComment-169417 Share on other sites More sharing options...
Tandem Posted January 26, 2007 Author Share Posted January 26, 2007 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 :PThanks for the replies. Quote Link to comment https://forums.phpfreaks.com/topic/35746-stopping-output/#findComment-169423 Share on other sites More sharing options...
boo_lolly Posted January 26, 2007 Share Posted January 26, 2007 [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 :PThanks for the replies.[/quote]you may get some use out of [url=http://php.net/exit]exit()[/url]. you may not =\ Quote Link to comment https://forums.phpfreaks.com/topic/35746-stopping-output/#findComment-169474 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.