PHP: Abort within include - continue remaining script
Question by Guest | 2016-07-24 at 10:45
I have a PHP script in which another script is inserted using include('script.php'). So far, it is working like I want.
However, the script included with include() should be canceled and discontinued under some circumstances.
Of course, I could no formulate if-statements for each condition, but this would make the script much more complicated because of the brackets would have to appear again at the end.
So, what I need is something like an exit-command. I have also already tried to use the exit and break functions of PHP, but this always breaks the entire script and not only the included one. The original script from which the include was called, should be continued further in each case.
Related Topics
Windows Batch Script: Computer Shutdown
Tutorial | 2 Comments
jQuery: Send HTML5 Canvas to Server via Ajax
Tutorial | 0 Comments
jQuery: Submit complete form and receive content with Ajax
Tutorial | 0 Comments
Send Form Input as an Array to PHP Script
Tip | 0 Comments
Textarea Maxlength: Limit Maximum Number of Characters in Textarea
Tutorial | 3 Comments
HTML Form: Redirection depending on Radiobutton or Checkbox State
Tutorial | 0 Comments
PHP: File Download Script
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Just try to use "return". With this, you can write as much termination conditions for your script as you want. Here is an example:
The actual code of the script will only be executed in that case if the "return" has not been triggered before. The superordinate script from which this script was called, will not be affected from that.
Another tip: It would be better to include the termination conditions in the super script because then you can save the processor from calling include(). This is better for your performance because the script file must only be searched for when it will also be used.
2016-07-25 at 08:53