这是我网站 map 的样子:
root:
-index.php
-\actions\ (various php files inside and a .htaccess)
- \includes\ (various php files inside and a .htaccess)
- .htaccess
我知道如果我在操作中使用“拒绝所有人”并包含目录,则其中的文件将受到保护,无法直接访问。
现在,我的 actions 文件夹中有许多由 index.php
(表单)调用的 php 文件。
我在 \actions
内的 .htaccess
中“拒绝所有人”,但后来我禁止访问该文件。
那么,我如何保护文件免受直接 url 访问,但有可以从 index.php
调用的异常?
最佳答案
最简单的方法是在 index.php 中放置一个常量,如果这个常量存在,则检查其他 php 文件。如果没有,让脚本死掉。
索引.php
define('APP', true);
各种.php
if(!defined('APP')) die();
关于php - 保护 php 文件不被直接访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17304979/