Prevent direct access to a php include file

后端 未结 30 1361
盖世英雄少女心
盖世英雄少女心 2020-11-22 06:32

I have a php file which I will be using as exclusively as an include. Therefore I would like to throw an error instead of executing it when it\'s accessed directly by typing

30条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 07:07

    What Joomla! does is defining a Constant in a root file and checking if the same is defined in the included files.

    defined('_JEXEC') or die('Restricted access');
    

    or else

    one can keep all files outside the reach of an http request by placing them outside the webroot directory as most frameworks like CodeIgniter recommend.

    or even by placing an .htaccess file within the include folder and writing rules, you can prevent direct access.

提交回复
热议问题