gpt4 book ai didi

php - 保护 php 文件不被直接访问

转载 作者:可可西里 更新时间:2023-10-31 22:12:27 25 4
gpt4 key购买 nike

这是我网站 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com