in PHP, how would one return from an included script back to the script where it had been included from?
IE:
1 - main script 2 - application 3 - included
Basically, I want to get back from 3 to 2, return() doesn't work.
Code in 2 - application
$page = "User Manager"; if($permission["13"] !=='1'){ include("/home/radonsys/public_html/global/error/permerror.php"); return(); }
The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.
The return keyword ends a function and, optionally, uses the result of an expression as the return value of the function. If return is used outside of a function, it stops PHP code in the file from running.
The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.
The include_once keyword is used to embed PHP code from another file. If the file is not found, a warning is shown and the program continues to run. If the file was already included previously, this statement will not include it again.
includeme.php:
$x = 5; return $x;
main.php:
$myX = require 'includeme.php';
also gives the same result
This is one of those little-known features of PHP, but it can be kind of nice for setting up really simple config files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With