Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Terminating PHP Script

Status
Not open for further replies.

kdshah

Programmer
Joined
Oct 15, 2002
Messages
8
Location
US
How can I terminate a PHP script prematurely based on some condition? At the same time, I would like to send some message to the user informing him of the reason of this premature termination..

For example

if (x>10)
echo "value greater than 9 is invalid";
//END PHP SCRIPT ( HOW TO DO ??)
else
//continue executing the script.

Thanks,
Kunal
 
if (x>10)
echo "value greater than 9 is invalid";
exit;
else
//continue executing the script.

 
Just FYI that I am looking for some method to end the script and not just a way of getting that example work.(coz in the example that I gave, an if else could have worked)

-Kunal
 
The die function does exactly what you want. It prints a message and terminates the script. The syntax is very easy:
Code:
die("Message");
//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top