1 <?php
  2 
  3 /*
  4     [Discuz!] (C)2001-2007 Comsenz Inc.
  5     This is NOT a freeware, use is subject to license terms
  6 
  7     $Id: common.inc.php 10344 2007-08-27 02:36:30Z monkey $
  8 */
  9 /*
 10 说明:
 11 Discuz!核心文件阅读;
 12 */
 13 error_reporting(0);    //对脚本的错误回显作了屏蔽,参数“0”的意思量关闭所有级别的错误报告。
 14 set_magic_quotes_runtime(0);//传入的参数“0”来关闭php的魔法引用,[这么做是禁止php解释对页面传递到服务器的参数进行处理,交由下面的Discuz!来过滤]
 15 $mtime = explode(' ', microtime());//使用一个字符串分割另一个字符串
 16 $discuz_starttime = $mtime[1] + $mtime[0];
 17 
 18 
 19 
 20 /*********************************************************************/
 21 /*
 22     这组全部是Discuz!的常量的定义;
 23 */
 24 
 25 define('SYS_DEBUG', FALSE);    //脚本量否运行在系统除错状态
 26 define('IN_DISCUZ', TRUE);    //定义了Discuz程序代码的运行范围,在此定义为true后就可以在其他的脚本程序中使用了;
 27 /*
 28     if(!defind('IN_DISCUZ')){
 29         exit('Access Denied');
 30     }
 31     //来判断是否处于Discuz的运行范围内,如果不是,则页面提示“Access Denied”并结束,这可以在一定程度上避免了脚本包含调用错误引起的被入侵;
 32 */
 33 
 34 /*
 35     DISCUZ_ROOT 定义了Discuz!脚本程序的相对目录的根目录的路径;例如我的这个discuz!的这个值就是;C:\AppServ\www\
 36 */
 37 define('DISCUZ_ROOT', substr(dirname(__FILE__), 0, -7));
 38 
 39 
 40 /*
 41 MAGIC_QUOTES_GPC被定义成了get_magic_quotes_gpc()的返回值,也就是以后用来获取运行运行环境中对GET,POST,COOKIES的变量是否进行了PHP的魔法引用;
 42 */
 43 define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
 44 
 45 
 46 !defined('CURSCRIPT') && define('CURSCRIPT', '');
 47 /********************************************************************/
 48 
 49 /********************************************************************/
 50 //这段代码的是保持与版本低于4.1.0的php运行环境的预定义变量名的兼容性;
 51 if(PHP_VERSION < '4.1.0') {
 52     $_GET = &$HTTP_GET_VARS;
 53     $_POST = &$HTTP_POST_VARS;
 54     $_COOKIE = &$HTTP_COOKIE_VARS;
 55     $_SERVER = &$HTTP_SERVER_VARS;
 56     $_ENV = &$HTTP_ENV_VARS;
 57     $_FILES = &$HTTP_POST_FILES;
 58 }
 59 /********************************************************************/
 60 
 61 
 62 /********************************************************************/
 63 //这段代码中是用来检查是否存在“$REQUEST['GLOBALS']”或是“$_FILES['GLOBALS']"如果不存在,程序将会退出并提示Request tainting attempted.【说明$RESQUEST全局数组中包含了php的使用的$_GET,$_POST,$COOKIE中的全部的内容】;
 64 if (isset($_REQUEST['GLOBALS']) OR isset($_FILES['GLOBALS'])) {
 65     exit('Request tainting attempted.');
 66 }
 67 /********************************************************************/
 68 
 69 /********************************************************************/
 70 //引用Discuz!的全局函数文件”global,func.php些文件内的内容我们可以看到这个文件名称的定义是文件名.func.php根据discuz!的文件命名说明,这个文件应该是discuz!自定义的函数库,或叫叫做是自定义的全局函数库;
 71 require_once DISCUZ_ROOT.'./include/global.func.php';
 72 /********************************************************************/
 73 
 74 
 75 /********************************************************************
 76 getrobot()函数如下:
 77 function getrobot() {
 78     if(!defined('IS_ROBOT')) {
 79         $kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla'; //正则表达式,搜索引擎标识;
 80         $kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';    //正则表达式,浏览器的标识符;
 81         if(preg_match("/($kw_browsers)/", $_SERVER['HTTP_USER_AGENT'])) {    //判断是哪一种浏览器来访问php程序
 82             define('IS_ROBOT', FALSE);
 83         } elseif(preg_match("/($kw_spiders)/", $_SERVER['HTTP_USER_AGENT'])) {
 84             define('IS_ROBOT', TRUE);
 85         } else {
 86             define('IS_ROBOT', FALSE);
 87         }
 88     }
 89     return IS_ROBOT;
 90 }
 91 由上面的函数的整体来看,getrobot()此函数是用来判断请求当前请求是否是客户端还是搜索引擎的机器人程序; 
 92 */
 93 define('ISROBOT', getrobot());
 94 /********************************************************************/
 95 
 96 /********************************************************************/
 97 //说明:判断是NOROBOT这个常量是不是已经定义了,如果他定义了并且值为true则header('HTTP/1.1 403 Forbidden');,出现这种情况可能是这里的资源不想被访问到;
 98 if(defined('NOROBOT') && ISROBOT) {
 99     exit(header("HTTP/1.1 403 Forbidden"));    //403错误是:资源不可用。服务器理解客户的请求,但拒绝处理它。
100 }
101 /********************************************************************/
102 /********************************************************************
103 daddslashes()函数:
104 
105 function daddslashes($string, $force = 0) {
106     !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
107     if(!MAGIC_QUOTES_GPC || $force) {
108         if(is_array($string)) {
109             foreach($string as $key => $val) {
110                 $string[$key] = daddslashes($val, $force);
111             }
112         } else {
113             $string = addslashes($string);
114         }
115     }
116     return $string;
117 }
118 看了这个函数可以看到,是一个过滤函数;
119 结合下面的代码可以知道,其作用是把”_COOKIE,_POST,_GET”三个数组变量中的每个不以下划线“_”开头的元素,使用这个函数来进行过虑;
120 
121 */
122 foreach(array('_COOKIE', '_POST', '_GET') as $_request) {
123     foreach($$_request as $_key => $_value) {
124         $_key{0} != '_' && $$_key = daddslashes($_value);
125     }
126 }
127 /*
128     小提示:
129     关于上foreach($$_request as...当中的这两个$$符号的意思;
130     
131     例子:
132         可变变量
133         $first ="hello";
134         $hello ="world";
135         echo $first." ".$$first;
136         结果是  hello world
137 
138         $$first就是$hello,因为$first的值是hello
139 */
140 
141 /*
142     接着判断"MAGIC_QUOTES_GPC"当中的值是否存在客户端提交过来的文件数组,如果条件成立的话,也使用这个函数进行过虑;
143 */
144 if (!MAGIC_QUOTES_GPC && $_FILES) {
145     $_FILES = daddslashes($_FILES);
146 }
147 /********************************************************************/
148 
149 /********************************************************************/
150 /*
151     说明这段代码就是用来初始化本文件中的要使用的到的配制信息;
152     参数说明:
153     $charset  //字符编码;
154     $dbcharset //数据库编码;
155     $forumfounders //论坛创始人 UID
156     $metakeywords //页面当中的Meta信息;
157     $extrahead //页面中付加在<head>当中的信息;
158     $seodescription //页面对搜索引擎的优化信息;
159 */
160 $charset = $dbcharset = $forumfounders = $metakeywords = $extrahead = $seodescription = '';
161 /*
162     参数说明:
163     $plugins    //插件信息完整数组信息;
164     $hooks        //插件信息钩子数组信息;
165     $jsmenu        //用于js代码的菜单内容信息数组;
166     $forum        // 
167     $thread        //
168     $language   //语言包数组;
169     $actioncode //动态代码数组;
170     $modactioncode //操作动作代码数组;
171     $lang        //语言包数组;
172 */
173 $plugins = $hooks = $admincp = $jsmenu = $forum = $thread = $language = $actioncode = $modactioncode = $lang = array();
174 
175 require_once DISCUZ_ROOT.'./config.inc.php';  //引用配制文件;
176 /*
177     参数说明:
178         $_DCOOKIE     //Discuz!自定义存放Cookie信息的数组;
179         $_DSESSION   //Discuz!自定义存放Session信息的数组;
180         $_DCACHE     //Discuz!自定义的存放系统缓存信息的数组;
181         $_DPLUGIN     //Discuz!算定义存放插件的数组;
182         $advilist     //Discuz!自定义存放广告的数组;    
183 */
184 $_DCOOKIE = $_DSESSION = $_DCACHE = $_DPLUGIN = $advlist = array();
185 /********************************************************************/

 

posted on 2014-02-18 23:21  BarneyX  阅读(315)  评论(0编辑  收藏  举报