How can PHP scripts be protected from unauthorized access to source code when included in a web server?

To protect PHP scripts from unauthorized access to source code when included in a web server, you can use the `define()` function to set a constant in the main PHP file and check for this constant in each included file. If the constant is not defined, the script will exit to prevent unauthorized access.

// main.php
define('MY_APP', true);

// included_file.php
if (!defined('MY_APP')) {
    die('Unauthorized access');
}

// Rest of the code for included_file.php