Loading...
 
Skip to main content

History: How to avoid direct access of a file

Source of version: 3 (current)

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


{CODE(caption="Put this at the top of the file, just after the copyrights")}// 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;
}{CODE}

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


{CODE(caption="Also seen..." colors="php")}// This script may only be included - so it is better to die if called directly.

$access->check_script($_SERVER['SCRIPT_NAME'], basename(__FILE__));{CODE}


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