How can PHP include or require statements prevent direct access to included files?

To prevent direct access to included files in PHP, you can use include or require statements within a conditional check that verifies if a specific constant or variable is defined. If the constant or variable is not defined, the script will exit to prevent direct access to the included file.

<?php
define('INCLUDED', true);

if (!defined('INCLUDED')) {
    exit('Direct script access not allowed');
}

// Your included file content here
?>