How to detect if a file is being included or directly ran

前端 未结 6 969
春和景丽
春和景丽 2021-01-20 00:09

I have a php file that I include in my php script, but I don\'t want people to be able to directly run the file(without being included). How can I prevent that from happenin

6条回答
  •  时光取名叫无心
    2021-01-20 00:47

    Make the included scripts not accessible via HTTP at all. E.g. by protecting the subfolder or moving them above the document root.

    If you cannot do that, define() something like IS_INCLUDED in your main script and exit; if this constant is not defined() in your included script.

提交回复
热议问题