How can you prevent the rest of the script from being affected when using exit() in an included PHP file?

When using exit() in an included PHP file, it will immediately terminate the script, preventing the rest of the code from executing. To prevent this from affecting the rest of the script, you can use a conditional check before calling exit() to ensure that it only exits the included file and not the entire script.

// Check if the current file is the main script before calling exit()
if (!defined('IN_MAIN_SCRIPT')) {
    exit();
}

// Include the file with exit() statement
include 'included_file.php';