Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个 PHP 页面,一个 index.php 和一个 content.php。我正在使用include("content.php");index.php 文件中的代码。是否可以检查用户是在 index.php 上还是直接访问 content.php ?
include("content.php");
基本上我想要做的是在 index.php 上显示 content.php 但如果用户直接转到 content.php 那么我不希望脚本做任何事情。
索引.php
$chk = 1 include("content.php");
内容.php
if ($chk < 1){ include('index.php'); exit; }
将此添加到您只想包含的页面
<?php if(!defined('MyConst')) { die('Direct access not permitted'); } ?>
然后在包含它的页面上添加
<?php define('MyConst', TRUE); ?>