我有一个PHP脚本,我喜欢它,以便它只显示这个特定的文本,如果你在浏览器中查看页面,它不包含在另一个脚本..
例如
//foo.php
<?php
if(!included){
echo "You can only see this if this is the page you're viewing";
}
?>
//bar.php
<?php
include 'foo.php';
?>
Run Code Online (Sandbox Code Playgroud)
现在,当你查看"bar.php"时,你不应该看到文本..但是如果你打开foo.php,你会......我怎么会这样做...?如果可能..
本身不可能,但如果您在网站上公开php页面,例如example.com/bar.php,您可以检查$_SERVER['SCRIPT_FILENAME']您是否使用Apache.
if (basename(__FILE__) != basename($_SERVER['SCRIPT_FILENAME'])) {
//this is included
}
Run Code Online (Sandbox Code Playgroud)