discuz X2 源代码分析----index.php
1.<?php2.
3./**
4.* [Discuz!] (C)2001-2099 Comsenz Inc.
5.* This is NOT a freeware, use is subject to license terms
6.*
7.* $Id: index.php 10420 2010-05-11 06:58:24Z zhaoxiongfei $
8.*/
9.//====加载全局配置====
10.
11.@include './config/config_global.php';
12.//====如果全局配置为空则说明系统尚未安装====
13.14.//====进一步检测是否存在install.lock文件,不存在则转向到install文件夹路径下的文件,存在则说明配置信息丢失====
15.
16.if(empty($_config)) {
17. if(!file_exists('./data/install.lock')) {
18. header('location: install');
19. exit;
20. } else {
21. error('config_notfound');
22. }
23.}
24.//====当前app名称====
25.$_t_curapp = '';
26.//====判断app绑定的域名====
27.foreach($_config['app']['domain'] as $_t_app => $_t_domain) {
28. if($_t_domain == $_SERVER['HTTP_HOST']) {
29. $_t_curapp = $_t_app;
30. break;
31. }
32.}
33.//====如果当前app名称为空或为default,则进一步判断配置信息,设置app名称为默认或forum====
34.if(empty($_t_curapp) || $_t_curapp == 'default') {
35. $_t_curapp = !empty($_config['app']['default']) ? $_config['app']['default'] : 'forum';
36.}
37.//====重写$_SERVER['PHP_SELF']系统变量====
38.$_SERVER['PHP_SELF'] = str_replace('index.php', $_t_curapp.'.php', $_SERVER['PHP_SELF']);
39.//====判断请求字符串是否为空,不为空则重写$_GET变量,指定系统下一步执行的方法和参数
40.if(!empty($_SERVER['QUERY_STRING'])) {
41. //====如果请求字符串为数字类型,则app名称为Home,调用spaceMOD,请求字符串作为uid传入====
42. if(is_numeric($_SERVER['QUERY_STRING'])) {
43. $_t_curapp = 'home';
44. $_GET = array('mod'=>'space', 'uid'=>$_SERVER['QUERY_STRING']);
45. //====如果请求字符串第一个字符为g且g之后的字符为数字则app名称为forum,调用groupMOD,请求字符串数字部分作为fid传入====
46. //====经过测试,请求url形如index.php?g56====
47. } elseif(strtolower($_SERVER['QUERY_STRING']{0}) == 'g' && is_numeric(substr($_SERVER['QUERY_STRING'], 1))) {
48. $_t_curapp = 'forum';
49. $_GET = array('mod'=>'group', 'fid'=>intval(substr($_SERVER['QUERY_STRING'], 1)));
50. //====原理同上====
51. } elseif(strtolower($_SERVER['QUERY_STRING']{0}) == 'f' && is_numeric(substr($_SERVER['QUERY_STRING'], 1))) {
52. $_t_curapp = 'forum';
53. $_GET = array('mod'=>'forumdisplay', 'fid'=>intval(substr($_SERVER['QUERY_STRING'], 1)));
54. //====原理同上====
55. } elseif(strtolower($_SERVER['QUERY_STRING']{0}) == 't' && is_numeric(substr($_SERVER['QUERY_STRING'], 1))) {
56. $_t_curapp = 'forum';
57. $_GET = array('mod'=>'viewthread', 'tid'=>intval(substr($_SERVER['QUERY_STRING'], 1)));
58. }
59.} else {
60. //====如果请求字符串为空=====
61. //====判断个人空间是否启用二级域名及二级域名的根域名,若启用则解析二级域名指向实际对应的homeAPP,调用spaceMOD====
62. if(!empty($_config['home']['allowdomain']) && !empty($_config['home']['domainroot'])) {
63. $_t_hosts = explode('.', $_SERVER['HTTP_HOST']);
64. $_t_domainroots = explode('.', $_config['home']['domainroot']);
65. $_t_domains = array_diff($_t_hosts, $_t_domainroots);
66. if($_t_domains && count($_t_domains) == 1) {
67. $_t_domain = array_shift($_t_domains);
68. $_t_holddomains = empty($_config['home']['holddomain'])?array():explode(',', $_config['home']['holddomain']);
69. if($_t_domain != 'www' && !in_array($_t_domain, $_t_holddomains)) {
70. $_t_curapp = 'home';
71. $_GET = array('mod'=>'space', 'domain'=>$_t_domain);
72. }
73. }
74. }
75.}
76.//====根据之前获得的app名称调用具体的app文件====
77.require './'.$_t_curapp.'.php';
78.
79.?>