What alternative methods can be used to secure included files in PHP instead of relying on htaccess?

When securing included files in PHP, one alternative method is to use PHP code to restrict direct access to the files. This can be achieved by defining a constant in the main PHP file and checking for its existence in the included files. If the constant is not defined, the included file will exit the script to prevent unauthorized access.

// main.php
define('SECURE_INCLUDE', true);
include 'included_file.php';

// included_file.php
if (!defined('SECURE_INCLUDE')) {
    exit('Direct script access not allowed');
}

// Rest of the code for included_file.php