I have done some research and found a way to prevent access to included files using the below code:

PHP Code:
if (count(get_included_files()) == 1) exit('Access denied.'); 

PHP Code:
if (count(get_included_files()) == 1header('Location: /* home page or login page */'); 
Is this a good or secure way to do prevent direct access to files that are not meant to be accessed directly such as PHP script files? Do you have any better alternative methods?