拒绝直接访问所有.php文件index.php的除外 [英] Deny direct access to all .php files except index.php
问题描述
我要拒绝直接访问所有的的.php
文件除了一个:的index.php
I want to deny direct access to all .php
files except one: index.php
其他的.php
文件的唯一途径应该是通过PHP 包括
。
The only access to the other .php
files should be through php include
.
如果可能,我希望在同一个文件夹中的所有文件。
If possible I want all files in the same folder.
更新:
一个一般的规则将是很好,所以我并不需要经过的所有文件。风险在于,我忘记了一个文件或线路。
A general rule would be nice, so I don't need to go through all files. The risk is that I forget a file or line.
更新2:
在的index.php
是一个文件夹中的 www.myadress.com/myfolder/index.php
我要拒绝访问所有的.php
文件 MyFolder中
和子文件夹该文件夹。
I want to deny access to all .php
files in myfolder
and subfolders to that folder.
推荐答案
在index.php文件,添加一个访问值,像这样的:
In index.php, add an access value like this:
$access = 'my_value';
在所有其他文件中,包括此检查之前甚至一个字节是呼应由PHP:
In every other file, include this check before even a single byte is echoed out by php:
if(empty($access)) {
header("location:index.php");
die();
}
这样一来,其他的PHP文件将只能通过需要/包括而不是通过URL。
This way, other php files will be accessible only through require / include and not through the url.
这篇关于拒绝直接访问所有.php文件index.php的除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!