【问题标题】:Check where page is being accessed from检查从哪里访问页面
【发布时间】: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 php-5.6


    【解决方案1】:

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

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

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

    <?php
        define('MyConst', TRUE);
    ?>
    

    【讨论】:

      【解决方案2】:

      index.php

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

      content.php

      if ($chk < 1){
        include('index.php');
        exit;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-24
        相关资源
        最近更新 更多