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
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]
Link to comment
Share on other sites

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?)

Link to comment
Share on other sites

[!--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 { }.
Link to comment
Share on other sites

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