Home  >  Article  >  Backend Development  >  define常量如何防止地址栏直接访问后台文件的

define常量如何防止地址栏直接访问后台文件的

WBOY
WBOYOriginal
2016-06-13 10:15:17673browse

define常量怎么防止地址栏直接访问后台文件的
define是不能跨页面的,但是最近看一个开源的PHP项目它是这样的:比如a.php :直接define('IN_TM', TRUE);
b.php直接if(!defined('IN_TM'))
{
exit('Access Denied');
}
if($_SESSION["admin"]!="Silence")
{
include template('login.htm');
  exit;
}。。。。。
就完全没用include包含!但是我这样模拟的时候define是不能跨页面的!它还有什么设置使得'IN_TM'在另一个页面有效吗?
类似于DISCUZ的防止地址栏直接访问后台文件又是怎么实现的呢?

------解决方案--------------------
如果你能确认在判断之前没有文件被显式的嵌入的话
那么他就是利用了 php.ini 中的 auto_prepend_file 

其实只要项目能运行, 你只需 打印出 get_included_files 的结果就知道什么文件被嵌入了

------解决方案--------------------
这个肯定有用include包含,只是你没看到
------解决方案--------------------
但是我这样模拟的时候define是不能跨页面的!它还有什么设置使得'IN_TM'在另一个页面有效吗?

b.php
if(!defined('IN_TM')) 
{
exit('Access Denied');
}

a.php
define('IN_TM', TRUE);
include 'b.php';

访问 b.php 必须通过访问 a.php 完成,否则就 Access Denied

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn