security - What's the safest method to access a php file thats outside the root directory? -
i've tried search elsewhere on stackoverflow , elsewhere on net.
can't seem solid lock on answer suggests it's safest way.
i know securest method is, possible, not include php files in root directory can helped.
so, trying find out is, if want include php file stored outside root directory, say, in directory, safest way me that?
this isn't going directly answer question, maybe @ app structure differently. think it's misconception it's not safe include files outside of webroot.
on contrary, many people have structure if not all of application logic outside of public_html
or similar directory. catch-all router type systems.
you can have structure like:
var www public something.js happy.jpg index.php application bootstrap.php awesomeclass.php router.php
now index.php
can work out real root of application.
something like:
define('web_root', __dir__); define('app_root', dirname(__dir__)); define('php_root', app_root . directory_separator . 'application');
you have constants point real filesystem path of public html directory , php files are, , can safely include files like:
include(php_root . directory_separator . 'bootstrap.php');
this safe, , many people have apps structured this. prevents people being able browse php files have laying around, in event don't have .htaccess
or similar voodoo in place.
Comments
Post a Comment