【发布时间】:2015-01-11 03:26:07
【问题描述】:
我有两个 PHP 页面,一个 index.php 和一个 content.php。我在 index.php 文件中使用代码include("content.php");。是否可以检查用户是在 index.php 上还是直接访问 content.php ?
基本上我想做的是在 index.php 上显示 content.php,但如果用户直接转到 content.php,那么我不希望脚本做任何事情。
【问题讨论】:
我有两个 PHP 页面,一个 index.php 和一个 content.php。我在 index.php 文件中使用代码include("content.php");。是否可以检查用户是在 index.php 上还是直接访问 content.php ?
基本上我想做的是在 index.php 上显示 content.php,但如果用户直接转到 content.php,那么我不希望脚本做任何事情。
【问题讨论】:
将此添加到您只想包含的页面
<?php
if(!defined('MyConst')) {
die('Direct access not permitted');
}
?>
然后在包含它的页面上添加
<?php
define('MyConst', TRUE);
?>
【讨论】:
index.php
$chk = 1
include("content.php");
content.php
if ($chk < 1){
include('index.php');
exit;
}
【讨论】: