Home  >  Article  >  Backend Development  >  这么做是为什么,帮忙看看好么 -

这么做是为什么,帮忙看看好么 -

WBOY
WBOYOriginal
2016-06-13 11:59:521187browse

这样做是为什么,帮忙看看好么 - -
defined ( 'IN' ) or die ( 'Access Denied' );
这句话。在前台控制器文件都有,但是为什么要这么做,他在index.php文件定义了这个常量,然后来检查他是否被定义,但是前台控制器本来就是用来访问的,为什么要加这个定义啊。不是根本没有用吗?
------解决方案--------------------
如果IN没有定义,则退出执行,并输出Access Denied

作用是当IN没有定义时,不执行后面的程序。

这样就会输出ok
define('IN', 123);
defined ( 'IN' ) or die ( 'Access Denied' );
echo 'ok';
如果define('IN', 123);这句不存在,就输出AccessDenied
------解决方案--------------------
这样做目的是控制入口,你的程序应该是只能用index.php?controller=xxx&action=xxx 形式访问的吧。
如果用户直接访问 controller.php 要被禁止。所以加了这段判断。

例如你的目录结构
app/controller/c.php
index.php

define('IN','xxx'); 这句在index.php定义
如果用户直接访问 index.php?controller=c 会执行 app/controller/c.php 因为IN有定义了,所以可以执行。
但用户直接访问app/controller/c.php 因为IN没有定义,所以不能执行。
------解决方案--------------------
凡是有这句的程序文件,都不能直接访问到
而只能在 index.php 中包含

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