Prevent direct access to a php include file

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

    I had this problem once, solved with:

    if (strpos($_SERVER['REQUEST_URI'], basename(__FILE__)) !== false) ...
    

    but the ideal solution is to place the file outside of the web-server document root, as mentioned in another anwser.

提交回复
热议问题