I need to block the directly access to some php files. Currently I ussing a constant to prevent this, but when I include the constant from the primary file and include again another php file the third file aren't taken the value of the constant.
Currently I'm running the script on XAMPP with php 7.3. Ordered as follows:
Project/
- index.php
- link.php
- inc/
- classes.php
- functions.php
index.php
define( '__PATH__', dirname( __FILE__ ) . '/' )
[...]
include ( 'link.php' );
link.php
if( ! defined('__PATH__') ) die('unatuhorized');
[...]
require( dirname(__FILE__) . DIRECTORY_SEPARATOR . 'inc/classes.php' );
Output
__PATH__ = bool true
/inc/classes.php
if( ! defined('__PATH__') ) die('unatuhorized');
Output
__PATH__ = Undefined constant __PATH__
Expected
__PATH__ = bool true/false
I want to...
Allow the access: to index.php
Block directly access to: link.php, inc/classes.php