PHP exit() from within included script, exit parent script?
Anyone know if it's possible to terminate a parent PHP script from within an included/required script?
You can use
die();
to end the furthur execution of any script at any point. Use of Die puts an end to the parent scripts as well.
die("End");
Will output "end".
You are looking for return
; command. This will terminate execution of only the child.php, and parent.php will be processed after that.
exit();
Will that terminate just child.php, or parent.php as well?
It will terminate the entire script.
If you don't want to do that, but return to the including script, you can return
from within an include.
You can use return if you need to exist included file but continue from main script.
return
(PHP 4, PHP 5, PHP 7)
return returns program control to the calling module.Execution resumes at the expression following the called module's invocation.
If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call. return also ends the execution of an eval() statement or script file.
If called from the global scope, then execution of the current script file is ended. If the current script file was included or required,then control is passed back to the calling file. Furthermore, if the current script file was included, then the value given to return will be returned as the value of the include call. If return is called from within the main script file, then script execution ends. If the current script file was named by the auto_prepend_file or auto_append_file configuration options in php.ini,then that script file's execution is ended