我的网站的主文件(index.php)代码在这里:
<?php
include 'header.php';
include 'sidebar.php';
include 'content.php';
include 'footer.php';
?>
Run Code Online (Sandbox Code Playgroud)
但我不希望任何用户通过编写"www.domain.com/header.php"来查看这些包含文件.我应该在这些文件中插入php代码还是可以的?
你有几个选择.
exit如果没有设置.这是给你的PHP.
if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){exit();}
Run Code Online (Sandbox Code Playgroud)
简而言之,如果调用文件本身,则退出执行.
资料来源:http://thephpcode.blogspot.se/2009/07/creating-include-only-php-files.html