禁用直接访问 php 文件,但不包括


Disable direct access php file but not include

我想禁用 PHPFox(phpfoxsite.com/static/ajax.php) 中的漏洞。 这是错误的一个例子 - http://seclists.org/bugtraq/2014/Apr/23

我的测试 :

在 .htaccess 中

Deny from all 

在 PHP 文件 ( ajax.php ) 中

if(count(get_included_files()) ==1) exit("Direct access not permitted.");

是否有已知的方法或解决此问题的方法?

谢谢

一个好主意是设置一个常量,只允许某些文件包含它:

索引.php:

define('ALLOWED_TO_INCLUDE_AJAX', true);
include('ajax.php');

阿贾克斯.php:

if(!defined('ALLOWED_TO_INCLUDE_AJAX')) exit(); // Silence is golden

由于您退出,因此不需要 .htaccess。