2

我有两个 PHP 页面,一个 index.php 和一个 content.php。我正在使用include("content.php");index.php 文件中的代码。是否可以检查用户是在 index.php 上还是直接访问 content.php ?

基本上我想要做的是在 index.php 上显示 content.php 但如果用户直接转到 content.php 那么我不希望脚本做任何事情。

4

2 回答 2

1

索引.php

$chk = 1
include("content.php");

内容.php

if ($chk < 1){
  include('index.php');
  exit;
}
于 2015-01-11T03:50:33.020 回答
1

将此添加到您只想包含的页面

<?php
if(!defined('MyConst')) {
    die('Direct access not permitted');
}
?>

然后在包含它的页面上添加

<?php
    define('MyConst', TRUE);
?>
于 2015-01-11T03:30:05.357 回答