用户
 找回密码
 入住 CI 中国社区
搜索
查看: 16012|回复: 7
收起左侧

php 语法问题?

[复制链接]
发表于 2009-3-1 16:03:15 | 显示全部楼层 |阅读模式
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

BASEPATH 指什么?
它是自定的variable?
发表于 2009-3-1 16:25:40 | 显示全部楼层
BASEPATH 是常量啊。
看看 PHP 手册 defined 函数的定义吧。
这句话的意思是防止非法访问当前的 PHP 文件。
发表于 2009-3-1 18:18:07 | 显示全部楼层
BASEPATH 是在 index.php 中定义的。
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
这一句要求此文件必须通过index.php 调用执行。
 楼主| 发表于 2009-3-1 20:53:25 | 显示全部楼层
BASEPATH 是在 index.php 中定义的。

Fanbin 发表于 2009-3-1 18:18


是否只要在index.php定义了BASEPATH, 在其他page 加上 if ( ! defined('BASEPATH')) exit('No directscript access allowed');
就可以防止非法进入?

以前我是用session防止的, 不知道哪种较好?
发表于 2009-3-1 23:06:36 | 显示全部楼层
对,只要加上 BASEPATH 就可以防止非法访问,只能从 index.php 访问了,呵呵。
发表于 2012-7-5 15:56:03 | 显示全部楼层
恩恩 学到了
发表于 2013-11-26 10:54:13 | 显示全部楼层
学习了
发表于 2014-2-14 10:10:18 | 显示全部楼层
这个存在于config.php里面,作用是外部访问只能通过index.php这个入口,保护其它文件的安全。BASEPATH就是index.php。我的理解

本版积分规则