master82 Posted March 8, 2006 Share Posted March 8, 2006 I've written a php script that contains a IF statement, if the output is False I need the script to stop/end at that point (ie not proceed to the end of the script).I've already echod a nice warning informing the person of the problem, I just need to know how to end it.Is there something like end() or stop() that can be used? (if so how)Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/4424-how-to-end-the-php-script/ Share on other sites More sharing options...
AV1611 Posted March 8, 2006 Share Posted March 8, 2006 quit()die()or you can do a <meta refresh and forward somewhere elseor a bunch of other things... what is best for you?[!--quoteo(post=352808:date=Mar 8 2006, 07:15 AM:name=master82)--][div class=\'quotetop\']QUOTE(master82 @ Mar 8 2006, 07:15 AM) [snapback]352808[/snapback][/div][div class=\'quotemain\'][!--quotec--]I've written a php script that contains a IF statement, if the output is False I need the script to stop/end at that point (ie not proceed to the end of the script).I've already echod a nice warning informing the person of the problem, I just need to know how to end it.Is there something like end() or stop() that can be used? (if so how)Thanks in advance![/quote] Quote Link to comment https://forums.phpfreaks.com/topic/4424-how-to-end-the-php-script/#findComment-15353 Share on other sites More sharing options...
master82 Posted March 8, 2006 Author Share Posted March 8, 2006 Thanks for the reply.I dont need to refresh, so I'll be using either quit() or die().do I simply just put:[code]if(expression) {echo "warning message here";quit();} else {[/code]or do i need to put something in the brackets (maybe the name of the php file?) Quote Link to comment https://forums.phpfreaks.com/topic/4424-how-to-end-the-php-script/#findComment-15364 Share on other sites More sharing options...
AV1611 Posted March 8, 2006 Share Posted March 8, 2006 This might me easier:[code]if(expression) {die('warning message here');}else{// Execute some other exciting code here!}[/code]or do i need to put something in the brackets (maybe the name of the php file?)[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/4424-how-to-end-the-php-script/#findComment-15367 Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352825:date=Mar 8 2006, 06:40 AM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 8 2006, 06:40 AM) [snapback]352825[/snapback][/div][div class=\'quotemain\'][!--quotec--]This might me easier:[code]if(expression) {die('warning message here');}else{// Execute some other exciting code here!}[/code]or do i need to put something in the brackets (maybe the name of the php file?)[/quote]You can skip the else { }. Quote Link to comment https://forums.phpfreaks.com/topic/4424-how-to-end-the-php-script/#findComment-15525 Share on other sites More sharing options...
AV1611 Posted March 8, 2006 Share Posted March 8, 2006 I left it purely for illustrative purposes... Quote Link to comment https://forums.phpfreaks.com/topic/4424-how-to-end-the-php-script/#findComment-15571 Share on other sites More sharing options...
lessthanthree Posted March 8, 2006 Share Posted March 8, 2006 You might actually want to use break; instead of die() or exit().Reason being, if you have other code to execute afterwards (even if it is just HTML to "complete" the page)break will finish it off whereas die and exit will both kill the script exactly where it is.If you are trying to make your webpages pass validation then it's pretty much essential that you don't exit a script without finishing the necasary html. In this case, break; is the best option. Of course, if it doesn't matter, and nothing else needs to be executed / printed, then die() and exit() are both fine.Phil. Quote Link to comment https://forums.phpfreaks.com/topic/4424-how-to-end-the-php-script/#findComment-15596 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.