当前位置: 首页 > article >正文

Discuz中的关键全局变量`$_G`

01-定义

$_G定义在discuz_application::_init_env()函数中,是一个array对象,$_G里面保存了许多预处理信息,缓存了很多配置。
定义文件:“\source\class\discuz\discuz_application.php” 115行,搜索“global $_G;
具体的定义如下:

		global $_G;
		$_G = array(
			'uid' => 0,
			'username' => '',
			'adminid' => 0,
			'groupid' => 1,
			'sid' => '',
			'formhash' => '',
			'connectguest' => 0,
			'timestamp' => TIMESTAMP,
			'starttime' => microtime(true),
			'clientip' => $this->_get_client_ip(),
			'remoteport' => $_SERVER['REMOTE_PORT'],
			'referer' => '',
			'charset' => '',
			'gzipcompress' => '',
			'authkey' => '',
			'timenow' => array(),
			'widthauto' => 0,
			'disabledwidthauto' => 0,

			'PHP_SELF' => '',
			'siteurl' => '',
			'siteroot' => '',
			'siteport' => '',

			'pluginrunlist' => !defined('PLUGINRUNLIST') ? array() : explode(',', PLUGINRUNLIST),

			'config' => & $this->config,
			'setting' => array(),
			'member' => array(),
			'group' => array(),
			'cookie' => array(),
			'style' => array(),
			'cache' => array(),
			'session' => array(),
			'lang' => 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','rate','pcomment','activity','reward','goods','at'),
				'interactive' => array('poke','friend','wall','comment','click','sharenotice'),
				'system' => array('system','credit','group','verify','magic','task','show','group','pusearticle','mod_member','blog','article'),
				'manage' => array('mod_member','report','pmreport'),
				'app' => array(),
			),
			'mobiletpl' => array('1' => 'touch', '2' => 'touch', '3' => 'touch', 'yes' => 'touch'),
		);
		$_G['PHP_SELF'] = dhtmlspecialchars($this->_get_script_url());
		$_G['basescript'] = CURSCRIPT;
		$_G['basefilename'] = basename($_G['PHP_SELF']);
		$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);
		}
		if(defined('IN_NEWMOBILE')) {
			$sitepath = preg_replace("/\/m/i", '', $sitepath);
		}
		$_G['isHTTPS'] = $this->_is_https();
		$_G['scheme'] = 'http'.($_G['isHTTPS'] ? 's' : '');
		$_G['siteurl'] = dhtmlspecialchars($_G['scheme'].'://'.$_SERVER['HTTP_HOST'].$sitepath.'/');

		$url = parse_url($_G['siteurl']);
		$_G['siteroot'] = isset($url['path']) ? $url['path'] : '';
		$_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;

	}

具体的各成员的意义见下面两个链接:
https://www.cnblogs.com/catyxiao/p/12777585.html
https://baike.baidu.com/item/%24_G/4218760

02具体的使用实例

01-$_G['forum']['ismoderator']

详见 https://blog.csdn.net/wenhao_ir/article/details/143388936


http://www.kler.cn/a/376594.html

相关文章:

  • MySQL数据库之存储过程的创建与应用
  • 什么是过拟合和欠拟合?什么会导致过拟合或欠拟合?
  • .NET Core WebApi第7讲:项目的发布与部署
  • 【Linux】编辑器vim 与 编译器gcc/g++
  • Ansible 部署应用
  • Linux 操作系统的诞生与发展历程
  • 快速上手 Windows 命令:简化你的工作流程
  • xlrd.biffh.XLRDError: Excel xlsx file; not supported
  • 你真的了解Canvas吗--解密十三【ZRender篇】
  • 简单了解前缀树/字典树(Trie树)C++代码
  • 三维重建:AI 根据图像信息还原物体三维形状的技术
  • postgresql14源码编译安装
  • 使用AMD GPU和ONNX Runtime高效生成图像与Stable Diffusion模型
  • 【前端】在 Next.js 开发服务器中应该如何配置 HTTPS?
  • 【前端】项目中遇到的问题汇总(长期更新)
  • 【Java】方法的使用 —— 语法要求、方法的重载和签名、方法递归
  • 无源元器件-磁珠选型参数总结
  • 基于vue框架的的考研网上辅导系统ao9z7(程序+源码+数据库+调试部署+开发环境)系统界面在最后面。
  • 复习回顾计划-vue篇
  • Word首行空格不显示空格符号问题
  • 2024 Rust现代实用教程Generic泛型
  • 解决pytorch问题:received an invalid combination of arguments - got
  • MFC图形函数学习03——画直线段函数
  • 【系统架构】如何演变系统架构:从单体到微服务
  • 前端好用的网站分享——CSS(持续更新中)
  • Three.js 开源项目及入门教程分享