wap_init.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. define("CTL",'ctl');
  10. define("ACT",'act');
  11. if(!defined('APP_ROOT_PATH'))
  12. define('APP_ROOT_PATH', str_replace('system/wap_init.php', '', str_replace('\\', '/', __FILE__)));
  13. require APP_ROOT_PATH.'system/define.php';
  14. if(IS_DEBUG){
  15. ini_set("display_errors", 1);
  16. error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
  17. }
  18. else
  19. error_reporting(0);
  20. require APP_ROOT_PATH.'public/directory_init.php';
  21. //关于session
  22. if(!class_exists("FanweSessionHandler"))
  23. {
  24. class FanweSessionHandler
  25. {
  26. private $savePath;
  27. private $mem; //Memcache使用
  28. private $db; //数据库使用
  29. private $table; //数据库使用
  30. private $prefix;
  31. function open($savePath, $sessionName)
  32. {
  33. $this->savePath = APP_ROOT_PATH.$GLOBALS['distribution_cfg']['SESSION_FILE_PATH'];
  34. $this->mem = new Rediscache($GLOBALS['distribution_cfg']['SESSION_CLIENT'], $GLOBALS['distribution_cfg']['SESSION_PORT'],$GLOBALS['distribution_cfg']['SESSION_PASSWORD']);
  35. $this->prefix = $GLOBALS['distribution_cfg']['REDIS_PREFIX'];
  36. return true;
  37. }
  38. function close()
  39. {
  40. return true;
  41. }
  42. function read($id)
  43. {
  44. $sess_id = "sess_".$id;
  45. return $this->mem->get("$this->prefix.$this->savePath/$sess_id");
  46. }
  47. function write($id, $data)
  48. {
  49. $sess_id = "sess_".$id;
  50. return $this->mem->set("$this->prefix.$this->savePath/$sess_id",$data,SESSION_TIME);
  51. }
  52. function destroy($id)
  53. {
  54. $sess_id = "sess_".$id;
  55. return $this->mem->delete("$this->prefix.$this->savePath/$sess_id");
  56. return true;
  57. }
  58. function gc($maxlifetime)
  59. {
  60. return true;
  61. }
  62. }
  63. }
  64. //关于session的开启
  65. function es_session_start()
  66. {
  67. session_set_cookie_params(0,$GLOBALS['distribution_cfg']['COOKIE_PATH'],$GLOBALS['distribution_cfg']['DOMAIN_ROOT'],false,true);
  68. if($GLOBALS['distribution_cfg']['SESSION_FILE_PATH']!=""||$GLOBALS['distribution_cfg']['SESSION_TYPE']=="MemcacheSASL"||$GLOBALS['distribution_cfg']['SESSION_TYPE']=="Rediscache"||$GLOBALS['distribution_cfg']['SESSION_TYPE']=="Db")
  69. {
  70. $handler = new FanweSessionHandler();
  71. session_set_save_handler(
  72. array($handler, 'open'),
  73. array($handler, 'close'),
  74. array($handler, 'read'),
  75. array($handler, 'write'),
  76. array($handler, 'destroy'),
  77. array($handler, 'gc')
  78. );
  79. }
  80. @session_start();
  81. }
  82. //es_session_start();
  83. if (PHP_VERSION >= '5.0.0')
  84. {
  85. $begin_run_time = @microtime(true);
  86. }
  87. else
  88. {
  89. $begin_run_time = @microtime();
  90. }
  91. @set_magic_quotes_runtime (0);
  92. define('MAGIC_QUOTES_GPC',get_magic_quotes_gpc()?True:False);
  93. if(!defined('IS_CGI'))
  94. define('IS_CGI',substr(PHP_SAPI, 0,3)=='cgi' ? 1 : 0 );
  95. if(!defined('_PHP_FILE_')) {
  96. if(IS_CGI) {
  97. //CGI/FASTCGI模式下
  98. $_temp = explode('.php',$_SERVER["PHP_SELF"]);
  99. define('_PHP_FILE_', rtrim(str_replace($_SERVER["HTTP_HOST"],'',$_temp[0].'.php'),'/'));
  100. }else {
  101. define('_PHP_FILE_', rtrim($_SERVER["SCRIPT_NAME"],'/'));
  102. }
  103. }
  104. if(!defined('APP_ROOT')) {
  105. // 网站URL根目录
  106. $_root = dirname(_PHP_FILE_);
  107. $_root = (($_root=='/' || $_root=='\\')?'':$_root);
  108. $_root = str_replace("/system","",$_root);
  109. $_root = str_replace("/wap","",$_root);
  110. $_root = str_replace("/mapi","",$_root);
  111. $_root = str_replace("/app","",$_root);
  112. define('APP_ROOT', $_root );
  113. }
  114. //引入时区配置及定义时间函数
  115. if(function_exists('date_default_timezone_set')){
  116. if(app_conf('DEFAULT_TIMEZONE')){
  117. date_default_timezone_set(app_conf('DEFAULT_TIMEZONE'));
  118. }else{
  119. date_default_timezone_set('PRC');
  120. }
  121. }
  122. //引入数据库的系统配置及定义配置函数
  123. require APP_ROOT_PATH.'system/common.php';
  124. define("NOW_TIME",get_gmtime()); //当前UTC时间戳
  125. define("CLIENT_IP",get_client_ip()); //当前客户端IP
  126. define("SITE_DOMAIN",get_domain()); //站点域名
  127. define("TIME_ZONE",app_conf('DEFAULT_TIMEZONE')); //时区
  128. $sys_config = require APP_ROOT_PATH.'system/config.php';
  129. //end 分布式
  130. function app_conf($name)
  131. {
  132. if(isset($GLOBALS['sys_config'][$name])){
  133. return stripslashes($GLOBALS['sys_config'][$name]);
  134. }else{
  135. return false;
  136. }
  137. }
  138. //定义$_SERVER['REQUEST_URI']兼容性
  139. if (!isset($_SERVER['REQUEST_URI']))
  140. {
  141. if (isset($_SERVER['argv']))
  142. {
  143. $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0];
  144. }
  145. else
  146. {
  147. $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
  148. }
  149. $_SERVER['REQUEST_URI'] = $uri;
  150. }
  151. filter_request($_GET);
  152. filter_request($_POST);
  153. //end 引入数据库的系统配置及定义配置函数
  154. require APP_ROOT_PATH.'system/db/db.php';
  155. require APP_ROOT_PATH.'system/utils/es_cookie.php';
  156. require APP_ROOT_PATH.'system/utils/es_session.php';
  157. //es_session::start();
  158. unset($_REQUEST['rewrite_param']);
  159. unset($_GET['rewrite_param']);
  160. //定义缓存
  161. //require APP_ROOT_PATH."system/cache/CacheRediscacheService.php";
  162. //$cache = new CacheRediscacheService();
  163. //$cache->celar_con();
  164. //end 定义缓存
  165. //定义DB
  166. define('DB_PREFIX', app_conf('DB_PREFIX'));
  167. if(IS_LONG_LINK_MYSQL){
  168. $pconnect = true;
  169. }else{
  170. $pconnect = false;
  171. }
  172. global $db;
  173. $db = new mysql_db(app_conf('DB_HOST').":".app_conf('DB_PORT'), app_conf('DB_USER'),app_conf('DB_PWD'),app_conf('DB_NAME'),'utf8',$pconnect);
  174. //end 定义DB
  175. //end 定义模板引擎
  176. $_REQUEST = array_merge($_GET,$_POST);
  177. filter_request($_REQUEST);