index.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. function isMobile()
  3. {
  4. // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
  5. if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
  6. {
  7. return true;
  8. }
  9. // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
  10. if (isset ($_SERVER['HTTP_VIA']))
  11. {
  12. // 找不到为flase,否则为true
  13. return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
  14. }
  15. // 脑残法,判断手机发送的客户端标志,兼容性有待提高
  16. if (isset ($_SERVER['HTTP_USER_AGENT']))
  17. {
  18. $clientkeywords = array ('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone','ipod', 'blackberry', 'meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile'
  19. );
  20. // 从HTTP_USER_AGENT中查找手机浏览器的关键字
  21. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
  22. {
  23. return true;
  24. }
  25. }
  26. // 协议法,因为有可能不准确,放到最后判断
  27. if (isset ($_SERVER['HTTP_ACCEPT']))
  28. {
  29. // 如果只支持wml并且不支持html那一定是移动设备
  30. // 如果支持wml和html但是wml在html之前则是移动设备
  31. if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
  32. {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. //if(isMobile()){
  39. // header("Location:http://m.9026.com");
  40. //}
  41. /**
  42. * [Discuz!] (C)2001-2099 Comsenz Inc.
  43. * This is NOT a freeware, use is subject to license terms
  44. *
  45. * $Id: index.php 34524 2014-05-15 04:42:23Z nemohou $
  46. */
  47. if(!empty($_SERVER['QUERY_STRING']) && is_numeric($_SERVER['QUERY_STRING'])) {
  48. $_ENV['curapp'] = 'home';
  49. $_GET = array('mod'=>'space', 'uid'=>$_SERVER['QUERY_STRING']);
  50. } else {
  51. $url = '';
  52. $domain = $_ENV = array();
  53. $jump = false;
  54. @include_once './data/sysdata/cache_domain.php';
  55. $_ENV['domain'] = $domain;
  56. if(empty($_ENV['domain'])) {
  57. $_ENV['curapp'] = 'forum';
  58. } else {
  59. $_ENV['defaultapp'] = array('portal.php' => 'portal', 'forum.php' => 'forum', 'group.php' => 'group', 'home.php' => 'home');
  60. $_ENV['hostarr'] = explode('.', $_SERVER['HTTP_HOST']);
  61. $_ENV['domainroot'] = substr($_SERVER['HTTP_HOST'], strpos($_SERVER['HTTP_HOST'], '.')+1);
  62. if(!empty($_ENV['domain']['app']) && is_array($_ENV['domain']['app']) && in_array($_SERVER['HTTP_HOST'], $_ENV['domain']['app'])) {
  63. $_ENV['curapp'] = array_search($_SERVER['HTTP_HOST'], $_ENV['domain']['app']);
  64. if($_ENV['curapp'] == 'mobile') {
  65. $_ENV['curapp'] = 'forum';
  66. if(!isset($_GET['mobile'])) {
  67. @$_GET['mobile'] = '2';
  68. }
  69. }
  70. if($_ENV['curapp'] == 'default' || !isset($_ENV['defaultapp'][$_ENV['curapp'].'.php'])) {
  71. $_ENV['curapp'] = '';
  72. }
  73. } elseif(!empty($_ENV['domain']['root']) && is_array($_ENV['domain']['root']) && in_array($_ENV['domainroot'], $_ENV['domain']['root'])) {
  74. $_G['setting']['holddomain'] = $_ENV['domain']['holddomain'] ? $_ENV['domain']['holddomain'] : array('www');
  75. $list = $_ENV['domain']['list'];
  76. if(isset($list[$_SERVER['HTTP_HOST']])) {
  77. $domain = $list[$_SERVER['HTTP_HOST']];
  78. switch($domain['idtype']) {
  79. case 'subarea':
  80. $_ENV['curapp'] = 'forum';
  81. $_GET['gid'] = intval($domain['id']);
  82. break;
  83. case 'forum':
  84. $_ENV['curapp'] = 'forum';
  85. $_GET['mod'] = 'forumdisplay';
  86. $_GET['fid'] = intval($domain['id']);
  87. break;
  88. case 'topic':
  89. $_ENV['curapp'] = 'portal';
  90. $_GET['mod'] = 'topic';
  91. $_GET['topicid'] = intval($domain['id']);
  92. break;
  93. case 'channel':
  94. $_ENV['curapp'] = 'portal';
  95. $_GET['mod'] = 'list';
  96. $_GET['catid'] = intval($domain['id']);
  97. break;
  98. case 'plugin':
  99. $_ENV['curapp'] = 'plugin';
  100. $_GET['id'] = $domain['id'];
  101. $_GET['fromapp'] = 'index';
  102. break;
  103. }
  104. } elseif(count($_ENV['hostarr']) > 2 && $_ENV['hostarr'][0] != 'www' && !checkholddomain($_ENV['hostarr'][0])) {
  105. $_ENV['prefixdomain'] = addslashes($_ENV['hostarr'][0]);
  106. $_ENV['domainroot'] = addslashes($_ENV['domainroot']);
  107. require_once './source/class/class_core.php';
  108. C::app()->init_setting = true;
  109. C::app()->init_user = false;
  110. C::app()->init_session = false;
  111. C::app()->init_cron = false;
  112. C::app()->init_misc = false;
  113. C::app()->init();
  114. $jump = true;
  115. $domain = C::t('common_domain')->fetch_by_domain_domainroot($_ENV['prefixdomain'], $_ENV['domainroot']);
  116. $apphost = $_ENV['domain']['app'][$domain['idtype']] ? $_ENV['domain']['app'][$domain['idtype']] : $_ENV['domain']['app']['default'];
  117. $apphost = $apphost ? 'http://'.$apphost.'/' : '';
  118. switch($domain['idtype']) {
  119. case 'home':
  120. if($_G['setting']['rewritestatus'] && in_array('home_space', $_G['setting']['rewritestatus'])) {
  121. $url = rewriteoutput('home_space', 1, $apphost, $domain['id']);
  122. } else {
  123. $url = $apphost.'home.php?mod=space&uid='.$domain['id'];
  124. }
  125. break;
  126. case 'group':
  127. if($_G['setting']['rewritestatus'] && in_array('group_group', $_G['setting']['rewritestatus'])) {
  128. $url = rewriteoutput('group_group', 1, $apphost, $domain['id']);
  129. } else {
  130. $url = $apphost.'forum.php?mod=group&fid='.$domain['id'].'&page=1';
  131. }
  132. break;
  133. }
  134. }
  135. } else {
  136. $jump = true;
  137. }
  138. if(empty($url) && empty($_ENV['curapp'])) {
  139. if(!empty($_ENV['domain']['defaultindex']) && !$jump) {
  140. if($_ENV['defaultapp'][$_ENV['domain']['defaultindex']]) {
  141. $_ENV['curapp'] = $_ENV['defaultapp'][$_ENV['domain']['defaultindex']];
  142. } else {
  143. $url = $_ENV['domain']['defaultindex'];
  144. }
  145. } else {
  146. if($jump) {
  147. $url = empty($_ENV['domain']['app']['default']) ? (!empty($_ENV['domain']['defaultindex']) ? $_ENV['domain']['defaultindex'] : 'forum.php') : 'http://'.$_ENV['domain']['app']['default'];
  148. } else {
  149. $_ENV['curapp'] = 'forum';
  150. }
  151. }
  152. }
  153. }
  154. }
  155. if(!empty($url)) {
  156. $delimiter = strrpos($url, '?') ? '&' : '?';
  157. if(isset($_GET['fromuid']) && $_GET['fromuid']) {
  158. $url .= sprintf('%sfromuid=%d', $delimiter, $_GET['fromuid']);
  159. } elseif(isset($_GET['fromuser']) && $_GET['fromuser']) {
  160. $url .= sprintf('%sfromuser=%s', $delimiter, rawurlencode($_GET['fromuser']));
  161. }
  162. header("HTTP/1.1 301 Moved Permanently");
  163. header("location: $url");
  164. } else {
  165. require './'.$_ENV['curapp'].'.php';
  166. }
  167. function checkholddomain($domain) {
  168. global $_G;
  169. $domain = strtolower($domain);
  170. if(preg_match("/^[^a-z]/i", $domain)) return true;
  171. $holdmainarr = empty($_G['setting']['holddomain']) ? array('www') : explode('|', $_G['setting']['holddomain']);
  172. $ishold = false;
  173. foreach ($holdmainarr as $value) {
  174. if(strpos($value, '*') === false) {
  175. if(strtolower($value) == $domain) {
  176. $ishold = true;
  177. break;
  178. }
  179. } else {
  180. $value = str_replace('*', '.*?', $value);
  181. if(@preg_match("/$value/i", $domain)) {
  182. $ishold = true;
  183. break;
  184. }
  185. }
  186. }
  187. return $ishold;
  188. }
  189. ?>