PHP:检查文件是否直接加载而不是包含? [英] PHP: Check if a file is loaded directly instead of including?

查看:166
本文介绍了PHP:检查文件是否直接加载而不是包含?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法阻止用户查看文件,但仍然将其作为 PHP中的其他文件使用的?

Is there a way to prevent a user viewing an file but still use it as included to another file in PHP?

推荐答案

如果您使用

define('APP_RAN'); 

在包含它的文件中,然后将

in the file that includes it and then put

if(!defined('APP_RAN')){ die(); }

或另外

defined('APP_RAN') or die();

(更容易阅读)

在包含的文件中,如果您直接访问它将会死亡。

in included files it would die if you access them directly.

将所有包含的内容

例如,如果您的索引页面位于

For example, if your index page is at

/my/server/domain/public_html

你应该把包含的文件放在



You should put the included files in

/my/server/domain/

这篇关于PHP:检查文件是否直接加载而不是包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆