Prevent direct access to a php include file

后端 未结 30 1009
盖世英雄少女心
盖世英雄少女心 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 06:59

    Actually my advice is to do all of these best practices.

    • Put the documents outside the webroot OR in a directory denied access by the webserver AND
    • Use a define in your visible documents that the hidden documents check for:
          if (!defined(INCL_FILE_FOO)) {
              header('HTTP/1.0 403 Forbidden');
              exit;
          }
    

    This way if the files become misplaced somehow (an errant ftp operation) they are still protected.

提交回复
热议问题