How to include files with die(); function?

If I understand correctly what you are trying to do then unfortunately it isn't possible.

die(); will stop the script from executing at the point from where it is called.


Non-English Speakers:

You can provide your question in your native language as well, and somebody here may be able to translate it for you. Just make your best effort to ask in English, and add your native tongue below.


If you would like to test whether the includes happened successfully, you can test the return value of the include function itself:

// http://us3.php.net/manual/en/function.include.php Example #4
if ((include 'file1.php') != 'OK') {
    die();
}

You may also consider require() instead of include() depending on your needs:

require() is identical to include() except upon failure it will also produce a fatal E_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue.


Here is how to include a file, or die with a message if the include fails code sample.

(include('file.php')) || die('Failed to include file!');