我有两个PHP页面,一个index.php和一个content.php。我在index.php文件上使用代码include("content.php");。有没有可能检查用户是在index.php上,还是直接访问了content.php?
基本上,我想做的是在index.php上显示content.php,但是如果用户直接转到content.php,那么我不想让脚本做任何事情。
发布于 2015-01-11 11:30:05
将此内容添加到您希望仅包含的页面中
<?php
if(!defined('MyConst')) {
die('Direct access not permitted');
}
?>然后在包含它的页面上添加
<?php
define('MyConst', TRUE);
?>发布于 2015-01-11 11:50:33
index.php
$chk = 1
include("content.php");content.php
if ($chk < 1){
include('index.php');
exit;
}https://stackoverflow.com/questions/27883677
复制相似问题