ECshop中defined('IN_ECS')的实现原理
2014-07-19 10:46
204 查看
在PHP中经常看到如下代码
实现的原因以及原理如下:
ecshop里的有些.php页是不需要用户通过url直接访问的,用来被其它页调用的,例如/includes/init.php,就不需要直接访问,通过url访问你的网址/includes/init.php是无意义的,所以我们在可以直接方问的php里加上define('IN_ECS', true);
例如在index.php中有如下代码,一开头就设置IN_ECS的值为true然后才去加载init.php这样init.php文件中IN_ECS的值就为true,这时候引入cls_mysql.php也可以引入,因为此时IN_ECS的值也是为true
在页面直接访问
出现这样的结果
在不能直接访问的php里加上
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
这样当直接访问init.php里就会显不
Hacking attempt
从页起到禁止访问的目的,而其它页面在调用init.php时是正常的
这样做更安全
这也是一种设计思想,防止其它文件不正常调用或者防止前台直接访问文件。
if (!defined('IN_ECS')) { die('Hacking attempt'); }
实现的原因以及原理如下:
ecshop里的有些.php页是不需要用户通过url直接访问的,用来被其它页调用的,例如/includes/init.php,就不需要直接访问,通过url访问你的网址/includes/init.php是无意义的,所以我们在可以直接方问的php里加上define('IN_ECS', true);
例如在index.php中有如下代码,一开头就设置IN_ECS的值为true然后才去加载init.php这样init.php文件中IN_ECS的值就为true,这时候引入cls_mysql.php也可以引入,因为此时IN_ECS的值也是为true
define('IN_ECS', true); require(dirname(__FILE__) . '/includes/init.php');
在页面直接访问
出现这样的结果
在不能直接访问的php里加上
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
这样当直接访问init.php里就会显不
Hacking attempt
从页起到禁止访问的目的,而其它页面在调用init.php时是正常的
这样做更安全
这也是一种设计思想,防止其它文件不正常调用或者防止前台直接访问文件。
相关文章推荐
- ECshop中defined('IN_ECS')的实现原理
- ECshop中defined('IN_ECS')的实现原理
- ecshop中define('IN_ECS', true)的作用
- if(!defined('IN_ECS')){die('Hacking attempt');}
- ecshop中define('IN_ECS', true)的作用
- Error registering bean with name 'dataSource' defined in class path resource
- Error creating bean with name 'sessionFactory' defined in ServletContext resource
- Error creating bean with name 'sessionFactory' defined in ServletContext resource
- Spring Error creating bean with name 'sessionFactory ' defined in ServletContext resource [/WEB-INF/
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContex
- How to resolve '_DllMain@12 already defined in xxx.obj' ?
- for bean with name 'permisAddAction' defined in ServletContext resource
- Error creating bean with name 'userService' defined in class path resource [beans.xml]: Unsatisfied dependency expressed through
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContex
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- How to resolve '_DllMain@12 already defined in xxx.obj' ?
- Error creating bean with name 'sessionFactory' defined in ServletContext resource
- Spring异常:Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.
- The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not refere
- Error creating bean with name 'org.apache.cxf.wsdl.WSDLManager' defined in class path resource