How to Disallow Direct Access to a File with PHP

Just include this PHP code at the top of your include file. <?php if (!empty($_SERVER['SCRIPT_FILENAME']) && ‘includefilename.php’ == basename($_SERVER['SCRIPT_FILENAME'])) die (‘Direct File Access Prohibited’); ?>