Jump to content

How to end the php script


master82

Recommended Posts

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!
Link to comment
https://forums.phpfreaks.com/topic/4424-how-to-end-the-php-script/
Share on other sites

quit()
die()
or you can do a <meta refresh and forward somewhere else
or 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]
[!--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 { }.
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.