[英]How can I prevent “include files” from being seen by users?
我网站的主文件(index.php)代码在这里:
<?php
include 'header.php';
include 'sidebar.php';
include 'content.php';
include 'footer.php';
?>
但我不希望任何用户通过编写“ www.domain.com/header.php”来查看这些包含文件。 我应该在这些文件中插入PHP代码还是可行的?
您有几种选择。
exit
。 这是适合您的PHP。
if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){exit();}
简而言之,如果调用文件本身,则退出执行。
来源: http : //thephpcode.blogspot.se/2009/07/creating-include-only-php-files.html
您可以在主文件中定义一个常量,并在包含的文件中使用它来确定是否确实包含了它们:
index.php
<?php
define('REALLY_INCLUDED', true);
include'header.php';
header.php
<?php
if(!defined('REALLY_INCLUDED') || !REALLY_INCLUDED) {
exit();
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.