我有像header.php
和的某些文件footer.php
.我想禁止从浏览器地址栏直接请求这些文件.
如果我include 'file.php'
在代码中,那么它应该包括在内,但是如果它是直接请求的,我不希望它被显示,因为它没有用处.可能吗?
提前致谢 :)
你可以按照可取的顺序做任何这些事情(从"好"到"它的作品"):
/somepath/example.com/htdocs/
映射到http://example.com/
:/somepath/example.com/htdocs/index.php
/somepath/example.com/includes/header.php
/somepath/example.com/includes/footer.php
index.php文件:
<?php require_once('../includes/header.php') ?>
Run Code Online (Sandbox Code Playgroud)
<Files (header|footer).php>
Deny from all
</Files>
index.php文件:
<?php define('INCLUDED_FROM_MAIN_FILE_EXAMPLE_COM',true) ?>
header.php文件:
<?php if (!defined('INCLUDED_FROM_MAIN_FILE_EXAMPLE_COM')) { die(); }