Posted on March 6, 2008February 11, 2018 How to Disallow Direct Access to a File with PHP Place this code at the top of your PHP script. if ( stristr( $_SERVER['SCRIPT_NAME'], basename( __FILE__ ) ) ) { exit( 'No direct script access allowed' ); }