pc_init.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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/pc_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. require_once APP_ROOT_PATH."system/cache/Rediscache/Rediscache.php";
  22. $redisdb = new Rediscache($GLOBALS['distribution_cfg']['RDB_CLIENT'], $GLOBALS['distribution_cfg']['RDB_PORT'],$GLOBALS['distribution_cfg']['RDB_PASSWORD']);
  23. //关于session
  24. if(!class_exists("FanweSessionHandler"))
  25. {
  26. class FanweSessionHandler
  27. {
  28. private $savePath;
  29. private $mem; //Memcache使用
  30. private $db; //数据库使用
  31. private $table; //数据库使用
  32. private $prefix;
  33. function open($savePath, $sessionName)
  34. {
  35. $this->savePath = APP_ROOT_PATH.$GLOBALS['distribution_cfg']['SESSION_FILE_PATH'];
  36. if($GLOBALS['distribution_cfg']['RDB_CLIENT']==$GLOBALS['distribution_cfg']['SESSION_CLIENT']){
  37. $this->mem = $GLOBALS['redisdb'];
  38. }else{
  39. $this->mem = new Rediscache($GLOBALS['distribution_cfg']['SESSION_CLIENT'], $GLOBALS['distribution_cfg']['SESSION_PORT'],$GLOBALS['distribution_cfg']['SESSION_PASSWORD']);
  40. }
  41. $this->prefix = $GLOBALS['distribution_cfg']['REDIS_PREFIX'];
  42. return true;
  43. }
  44. function close()
  45. {
  46. return true;
  47. }
  48. function read($id)
  49. {
  50. $sess_id = "sess_".$id;
  51. return $this->mem->get("$this->prefix.$this->savePath/$sess_id");
  52. }
  53. function write($id, $data)
  54. {
  55. $sess_id = "sess_".$id;
  56. return $this->mem->set("$this->prefix.$this->savePath/$sess_id",$data,SESSION_TIME);
  57. }
  58. function destroy($id)
  59. {
  60. $sess_id = "sess_".$id;
  61. return $this->mem->delete("$this->prefix.$this->savePath/$sess_id");
  62. return true;
  63. }
  64. function gc($maxlifetime)
  65. {
  66. return true;
  67. }
  68. }
  69. }
  70. //关于session的开启
  71. function es_session_start()
  72. {
  73. session_set_cookie_params(0,$GLOBALS['distribution_cfg']['COOKIE_PATH'],$GLOBALS['distribution_cfg']['DOMAIN_ROOT'],false,true);
  74. 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")
  75. {
  76. $handler = new FanweSessionHandler();
  77. session_set_save_handler(
  78. array($handler, 'open'),
  79. array($handler, 'close'),
  80. array($handler, 'read'),
  81. array($handler, 'write'),
  82. array($handler, 'destroy'),
  83. array($handler, 'gc')
  84. );
  85. }
  86. @session_start();
  87. }
  88. /* sdk 版本登陆,session_id一致性
  89. $sess_id = trim($_REQUEST['session_id']);
  90. if($sess_id){
  91. session_id($sess_id);
  92. }*/
  93. es_session_start();
  94. if (PHP_VERSION >= '5.0.0')
  95. {
  96. $begin_run_time = @microtime(true);
  97. }
  98. else
  99. {
  100. $begin_run_time = @microtime();
  101. }
  102. @set_magic_quotes_runtime (0);
  103. define('MAGIC_QUOTES_GPC',get_magic_quotes_gpc()?True:False);
  104. if(!defined('IS_CGI'))
  105. define('IS_CGI',substr(PHP_SAPI, 0,3)=='cgi' ? 1 : 0 );
  106. if(!defined('_PHP_FILE_')) {
  107. if(IS_CGI) {
  108. //CGI/FASTCGI模式下
  109. $_temp = explode('.php',$_SERVER["PHP_SELF"]);
  110. define('_PHP_FILE_', rtrim(str_replace($_SERVER["HTTP_HOST"],'',$_temp[0].'.php'),'/'));
  111. }else {
  112. define('_PHP_FILE_', rtrim($_SERVER["SCRIPT_NAME"],'/'));
  113. }
  114. }
  115. if(!defined('APP_ROOT')) {
  116. // 网站URL根目录
  117. $_root = dirname(_PHP_FILE_);
  118. $_root = (($_root=='/' || $_root=='\\')?'':$_root);
  119. $_root = str_replace("/system","",$_root);
  120. $_root = str_replace("/wap","",$_root);
  121. $_root = str_replace("/mapi","",$_root);
  122. define('APP_ROOT', $_root );
  123. }
  124. //引入时区配置及定义时间函数
  125. if(function_exists('date_default_timezone_set')){
  126. if(app_conf('DEFAULT_TIMEZONE')){
  127. date_default_timezone_set(app_conf('DEFAULT_TIMEZONE'));
  128. }else{
  129. date_default_timezone_set('PRC');
  130. }
  131. }
  132. //引入数据库的系统配置及定义配置函数
  133. require APP_ROOT_PATH.'system/common.php';
  134. define("NOW_TIME",get_gmtime()); //当前UTC时间戳
  135. define("CLIENT_IP",get_client_ip()); //当前客户端IP
  136. define("SITE_DOMAIN",get_domain()); //站点域名
  137. define("TIME_ZONE",app_conf('DEFAULT_TIMEZONE')); //时区
  138. $sys_config = require APP_ROOT_PATH.'system/config.php';
  139. //end 分布式
  140. function app_conf($name)
  141. {
  142. if(isset($GLOBALS['sys_config'][$name])){
  143. return stripslashes($GLOBALS['sys_config'][$name]);
  144. }else{
  145. return false;
  146. }
  147. }
  148. //定义$_SERVER['REQUEST_URI']兼容性
  149. if (!isset($_SERVER['REQUEST_URI']))
  150. {
  151. if (isset($_SERVER['argv']))
  152. {
  153. $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0];
  154. }
  155. else
  156. {
  157. $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
  158. }
  159. $_SERVER['REQUEST_URI'] = $uri;
  160. }
  161. filter_request($_GET);
  162. filter_request($_POST);
  163. //end 引入数据库的系统配置及定义配置函数
  164. require APP_ROOT_PATH.'system/db/db.php';
  165. require APP_ROOT_PATH.'system/utils/es_cookie.php';
  166. require APP_ROOT_PATH.'system/utils/es_session.php';
  167. //es_session::start();
  168. unset($_REQUEST['rewrite_param']);
  169. unset($_GET['rewrite_param']);
  170. //定义缓存
  171. require APP_ROOT_PATH."system/cache/CacheRediscacheService.php";
  172. $cache = new CacheRediscacheService();
  173. //$cache->celar_con();
  174. //end 定义缓存
  175. //定义DB
  176. define('DB_PREFIX', app_conf('DB_PREFIX'));
  177. if(IS_LONG_LINK){
  178. $pconnect = true;
  179. }else{
  180. $pconnect = false;
  181. }
  182. $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);
  183. //end 定义DB
  184. //end 定义模板引擎
  185. $_REQUEST = array_merge($_GET,$_POST);
  186. filter_request($_REQUEST);