Loading...
 
Skip to main content

How to avoid direct access of a file

We can't be sure that .inc files are not directly accessible. So:

Put this at the top of the file, just after the copyrights
Copy to clipboard
// This script may only be included - so its better to die if called directly. if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) { header('location: index.php'); exit; }


An example: http://tikiwiki.svn.sourceforge.net/viewvc/tikiwiki/trunk/admin/include_fgal.php?view=markupQuestion

Also seen...
Copy to clipboard
// This script may only be included - so it is better to die if called directly. $access->check_script($_SERVER['SCRIPT_NAME'], basename(__FILE__));



If you call the file include_permission_print.php instead of permission_print.php.inc, it will look good in the directory as well 😊

Show PHP error messages