cpliu903 发表于 2009-3-1 16:03:15

php 语法问题?

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

BASEPATH 指什么?
它是自定的variable吗?

Hex 发表于 2009-3-1 16:25:40

BASEPATH 是常量啊。
看看 PHP 手册 defined 函数的定义吧。
这句话的意思是防止非法访问当前的 PHP 文件。

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

BASEPATH 是在 index.php 中定义的。
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
这一句要求此文件必须通过index.php 调用执行。

cpliu903 发表于 2009-3-1 20:53:25

BASEPATH 是在 index.php 中定义的。

Fanbin 发表于 2009-3-1 18:18 http://codeigniter.org.cn/forums/images/common/back.gif

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

以前我是用session防止的, 不知道哪种较好?

Hex 发表于 2009-3-1 23:06:36

对,只要加上 BASEPATH 就可以防止非法访问,只能从 index.php 访问了,呵呵。

一朵忧郁的男子 发表于 2012-7-5 15:56:03

恩恩 学到了:hug:

小烦人精 发表于 2013-11-26 10:54:13

学习了{:1_1:}

天生我才 发表于 2014-2-14 10:10:18

这个存在于config.php里面,作用是外部访问只能通过index.php这个入口,保护其它文件的安全。BASEPATH就是index.php。我的理解
页: [1]
查看完整版本: php 语法问题?