I have a script: mainfile.php: <? echo "Hello world!"; include ("file2.php"); echo "Blah blah blah"; echo "Do other things.."; ?> Code (markup): file2.php: <? $yes=1; if($yes == "1") { echo "<br>How are you?"; exit; } ?> Code (markup): I basically want that "exit;" to be the end-all and cut the rest of the script (inside mainfile.php). This is not the actual script, just a re-enactment of the problem. Feedback/help appreciated! -Refined
2refined: I cannot not see any problems with given examples, exit() works as it should - it terminates the whole script. The die() function is just an alias for exit().
He is right. When you include a file in another file, the PHP interpretor treats it as one file. In this case, following is the code that PHP interprets: <? echo "Hello world!"; $yes=1; if($yes == "1") { echo "<br>How are you?"; exit; } echo "Blah blah blah"; echo "Do other things.."; ?> Code (markup): So, no code will be executed after exit().
Yes, this should indeed stop the whole file. If you just wanted to cut the included file short, then you can use return in the global scope.