index.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // $Id$
  12. // 定义ThinkPHP框架路径
  13. define('BASE_PATH','./');
  14. define('THINK_PATH', './ThinkPHP');
  15. //定义项目名称和路径
  16. define('APP_NAME', 'install');
  17. define('APP_PATH', '.');
  18. define('APP_ROOT_PATH', str_replace('install/index.php', '', str_replace('\\', '/', __FILE__)));
  19. require APP_ROOT_PATH.'system/define.php';
  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(isset($GLOBALS['redisdb'])){
  37. $this->mem = $GLOBALS['redisdb'];
  38. }else{
  39. $this->mem = new Rediscache($GLOBALS['distribution_cfg']['CACHE_CLIENT'], $GLOBALS['distribution_cfg']['CACHE_PORT'],$GLOBALS['distribution_cfg']['CACHE_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. es_session_start();
  89. // 加载框架入口文件
  90. require(THINK_PATH."/ThinkPHP.php");
  91. //实例化一个网站应用实例
  92. $AppWeb = new App();
  93. //应用程序初始化
  94. $AppWeb->run();
  95. ?>