<?php class discuz_application extends discuz_base { var $mem = null; var $session = null; var $config = array(); var $var = array(); var $cachelist = array(); var $init_db = true; var $init_setting = true; var $init_user = true; var $init_session = true; var $init_cron = true; var $init_misc = true; var $init_mobile = true; var $initated = false; var $superglobal = array( 'GLOBALS' => 1, '_GET' => 1, '_POST' => 1, '_REQUEST' => 1, '_COOKIE' => 1, '_SERVER' => 1, '_ENV' => 1, '_FILES' => 1, ); public function __construct() { $this->_init_env(); $this->_init_config(); $this->_init_input(); $this->_init_output(); } private function _init_env() { error_reporting(E_ERROR); //bool set_magic_quotes_runtime(bool $new_setting) //设置当前magic_quotes_runtime配置选项的激活状态。 //new_setting 关闭是false,开启是true。 //成功时返回true,或者在失败时返回false。 //自PHP5.3起,该函数已经被弃用,执行它的时候会抛出E_DEPRECATED异常。 //自PHP5.4起,尝试开启magic quotes时该函数会产生一个E_CORE_ERROR错误。 //E_DEPRECATED 运行时通知。启用后将会对在未来版本中可能无法正常工作的代码给出警告。 //E_CORE_ERROR 在PHP初始化启动过程中发生的致命错误。该错误类似E_ERROR,但是是由PHP引擎核心产生的。 if (PHP_VERSION < '5.3.0') { set_magic_quotes_runtime(0); } //bool get_magic_quotes_gpc(void) //如果magic_quotes_gpc为关闭时返回0,否则返回1。 //在PHP5.4.0始终返回false,因为这个魔术引号功能已经从PHP中移除了。 define('MAGIC_QUOTES_GPC', function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()); //string iconv(string $in_charset, string $out_charset, string $str) //将字符串str从in_charset转换编码到out_charset //in_charset 输入的字符集 //out_charset 输出的字符集 //如果你在out_charset后添加了字符串//TRANSLIT,将启用转写(transliteration)功能。这个意思是,当一个字符不能被目标字符集所表示时,它可以通过一个或多个形似的字符来近似表达。如果你添加了字符串//IGNORE,不能以目标字符集表达的字符将被默默丢弃。否则,会导致一个E_NOTICE并返回FALSE。 define('ICONV_ENABLE', function_exists('iconv')); //string mb_convert_encoding(string $str, string $to_encoding, [,mixed $from_encoding = mb_internal_encoding()]) //将string类型str的字符编码从可选的from_encoding转换到to_encoding。 //from_encoding 在转换前通过字符代码名称来指定。它可以是一个array也可以是逗号分隔的枚举列表。如果没有提供from_encoding,则会使用内部(internal)编码。 define('MB_ENABLE', function_exists('mb_convert_encoding')); //string ob_gzhandler(string $buffer, int $mode) //ob_gzhandler()目的是用在ob_start()中作回调函数,以方便将gz编码的数据发送到支持压缩页面的浏览器。 //在ob_gzhandler()真正发送压缩过的数据之前,该函数会确定(判定)浏览器可以接受哪种类型内容编码("gzip"、"deflate",或者根本什么都不支持),然后返回相应的输出。所有可以发送正确头信息表明他自己可以接受压缩的网页的浏览器,都可以支持。如果一个浏览器不支持压缩过的页面,此函数返回false。 define('EXT_OBGZIP', function_exists('ob_gzhandler')); define('TIMESTAMP', time()); $this->timezone_set(); //引入了公共函数库 if (!defined('DISCUZ_CORE_FUNCTION') && !@include(DISCUZ_ROOT.'./source/function/function_core.php')) { exit('function_core.php is missing'); } //设置PHP脚本使用128M内存 if (function_exists('ini_get')) { $memorylimit = @ini_get('memory_limit');//128M if($memorylimit && return_bytes($memorylimit) < 33554432 && function_exists('ini_set')) { ini_set('memory_limit', '128m'); } } //判断是否为蜘蛛爬行 define('IS_ROBOT', checkrobot()); //只允许的全局变量(_GET,_POST,_REQUEST,_COOKIE,_SERVER,_ENV,_FILES) foreach ($GLOBALS as $key => $value) { if (!isset($this->superglobal[$key])) { $GLOBALS[$key] = null; unset($GLOBALS[$key]); } } //定义了一个全局变量$_G,将这个全局变量按址传递给了$this->var,看来在模板中可以直接使用这些变量了。 global $_G; $_G = array( "uid"=>0,"username"=>"","adminid"=>0,"groupid"=>1,"sid"=>"", "formhash"=>"", "connectguest"=>0, "timestamp"=>TIMESTAMP, //mixed microtime([bool $get_as_float]) //microtime()当前Unix时间戳以及微秒数。本函数仅在支持gettimeofday()系统调用的操作系统下可用。 //如果调用时不带可选参数,本函数以 "msec sec" 的格式返回一个字符串,其中 sec 是自Unix纪元(0:00:00 January 1, 1970 GMT)起到现在的秒数,msec是微秒部分。字符串的两部分都是以秒为单位返回的。 //如果给出了 get_as_float 参数并且其值等价于TRUE,microtime()将返回一个浮点数。 //用 microtime() 对脚本的运行计时 "starttime"=>microtime(true), "clientip"=>$this->_get_client_ip(),//返回客户端IP地址 "remoteport"=>$_SERVER["REMOTE_PORT"],//返回访问页面的用户机的端口 'referer'=>'', 'charset'=>'', 'gzipcompress'=>'',//gzip压缩 'authkey'=>'', 'timenow'=>array(), 'widthauto'=>0, 'disabledwidthauto'=>0, 'PHP_SELF'=>'', 'siteurl'=>'', 'siteroot'=>'', 'siteport'=>'', //以上四个元素的值在本方法中设置 'pluginrunlist'=>!defined('PLUGINRUNLIST') ? array() : explode(',', PLUGINRUNLIST), 'config'=>array(), 'setting'=>array(), 'member'=>array(), 'group'=>array(), 'cookie'=>array(), 'style'=>array(), 'cache'=>array(), 'session'=>array(), 'lang'=>array(), 'my_app'=>array(), 'my_userapp'=>array(), 'fid'=>0, 'tid'=>0, 'forum'=>array(), 'thread'=>array(), 'rssauth'=>'', 'home'=>array(), 'space'=>array(), 'block'=>array(), 'article'=>array(), 'action'=>array('action'=>APPTYPEID,'fid'=>0,'tid'=>0,), 'mobile'=>'', 'notice_structure'=>array( 'mypost'=>array('post','pcomment','activity','reward','goods','at'), 'interactive'=>array('poke','friend','wall','comment','click','sharenotice'), 'system'=>array('system','myapp','credit','group','verify','magic','task','show','group','pusearticle','mod_member','blog','article'), 'manage'=>array('mod_member','report','pmreport'), 'app'=>array(), ), 'mobiletpl'=>array('1'=>'mobile','2'=>'touch','3'=>'wml','yes'=>'mobile'), ); $_G['PHP_SELF'] = dhtmlspecialchars($this->_get_script_url());//值为"/forum.php" $_G['basescript'] = CURSCRIPT;//常量CURSCRIPT在/forum.php文件中定义,值为"forum" $_G['basefilename'] = basename($_G['PHP_SELF']);//值为"forum.php" $sitepath = substr($_G['PHP_SELF'], 0, strrpos($_G['PHP_SELF'], '/'));//值为空字符串 //条件不满足未执行的代码 if (defined('IN_API')) { $sitepath = preg_replace("/\/api\/?.*?$/i", '', $sitepath); } elseif (defined('IN_ARCHIVER')) { $sitepath = preg_replace("/\/archiver/i", '', $sitepath); } //未执行的代码结束 $_G['isHTTPS'] = ($_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false; $_G['scheme'] = 'http'.($_G['isHTTPS'] ? 's' : ''); //$_SERVER["HTTP_HOST"]主机名称(它可以是localhost或www.example.com) $_G['siteurl'] = dhtmlspecialchars($_G['scheme'].'://'.$_SERVER['HTTP_HOST'].$sitepath.'/'); $url = parse_url($_G['siteurl']); $_G['siteroot'] = isset($url['path']) ? $url['path'] : ''; //Web服务器使用的端口,默认值为80。 //如果使用SSL安全连接,则这个值为用户设置的HTTP端口。 $_G['siteport'] = empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] == '443' ? '' : ':'.$_SERVER['SERVER_PORT']; if (defined('SUB_DIR')) { $_G['siteurl'] = str_replace(SUB_DIR, '/', $_G['siteurl']); $_G['siteroot'] = str_replace(SUB_DIR, '/', $_G['siteroot']); } $this->var = & $_G; } } ?>
<?php //_init_env()方法执行完之后,$_G变量都有哪些值?以下打印出在_init_env()方法执行完之后$_G全局变量所存储的值,此时C::app()->var按址引用$_G。 $_G = array ( 'uid' => 0, 'username' => '', 'adminid' => 0, 'groupid' => 1, 'sid' => '', 'formhash' => '', 'connectguest' => 0, 'timestamp' => 1498467762, 'starttime' => 1498467762.083, 'clientip' => '127.0.0.1', 'remoteport' => '61856', 'referer' => '', 'charset' => '', 'gzipcompress' => '', 'authkey' => '', 'timenow' => array (), 'widthauto' => 0, 'disabledwidthauto' => 0, 'PHP_SELF' => '/forum.php', 'siteurl' => 'http://www.pcool.com/', 'siteroot' => '/', 'siteport' => '', 'pluginrunlist' => array (), 'config' => array (), 'setting' => array (), 'member' => array (), 'group' => array (), 'cookie' => array (), 'style' => array (), 'cache' => array (), 'session' => array (), 'lang' => array (), 'my_app' => array (), 'my_userapp' => array (), 'fid' => 0, 'tid' => 0, 'forum' => array (), 'thread' => array (), 'rssauth' => '', 'home' => array (), 'space' => array (), 'block' => array (), 'article' => array (), 'action' => array ( 'action' => 2, 'fid' => 0, 'tid' => 0, ), 'mobile' => '', 'notice_structure' => array ( 'mypost' => array ( 0 => 'post', 1 => 'pcomment', 2 => 'activity', 3 => 'reward', 4 => 'goods', 5 => 'at', ), 'interactive' => array ( 0 => 'poke', 1 => 'friend', 2 => 'wall', 3 => 'comment', 4 => 'click', 5 => 'sharenotice', ), 'system' => array ( 0 => 'system', 1 => 'myapp', 2 => 'credit', 3 => 'group', 4 => 'verify', 5 => 'magic', 6 => 'task', 7 => 'show', 8 => 'group', 9 => 'pusearticle', 10 => 'mod_member', 11 => 'blog', 12 => 'article', ), 'manage' => array ( 0 => 'mod_member', 1 => 'report', 2 => 'pmreport', ), 'app' => array (), ), 'mobiletpl' => array ( 1 => 'mobile', 2 => 'touch', 3 => 'wml', 'yes' => 'mobile', ), 'basescript' => 'forum', 'basefilename' => 'forum.php', 'isHTTPS' => false, 'scheme' => 'http', ); ?>