1. ecshop init.php file analysis
2. 3.
4. /**
5. * ECSHOP front-end public files
6. *
================================ ==========================================
=
7. * Copyright 2005-2008 Shanghai Shangpai Network Technology Co., Ltd., and all rights reserved.
8. * Website address: [url]http://www.ecshop.com[/url];
9. * ------------------ -------------------------------------------------- --------
10. * This is not a free software! You may only modify and use the program code
11. * on the premise that it is not used for commercial purposes; redistribution of the program code in any form or for any purpose is not allowed.
12. *
============================================ ==================================
=
13. * $Author: likai $
14. * $Id: init.php 16132 2009-05-31 08:59:15Z likai $
15.*/
16.
17 . // Cross-domain import of files is prohibited.
18. if (!defined('IN_ECS')){
19. die('Hacking attempt'); // Hacking attempt
20. }
21.
22. // Useless code, later function coverage
23. error_reporting(E_ALL);
24.
25. // Prevent novices from changing this variable from GET POST or new constant Definition.
26. if (__FILE__ == ''){
27. die('Fatal error code: 0');
28. }
29.
30. /* Obtaining the root directory of the current ecshop is more complicated than discuz */
31. define('ROOT_PATH', str_replace('includes/init.php', '', str_replace('', '/', __FILE__))) ;
32.
33. // Determine that the install file in the data directory does not exist && The installation lock file in include does not exist and the
NO_CHECK_INSTALL constant is not defined, so jump to the installation page.
34. if (!file_exists(ROOT_PATH . 'data/install.lock') && !file_exists(ROOT_PATH . 'includes/install.lock')
35. && !defined('NO_CHECK_INSTALL'))
36. {
37. header("Location: ./install/index.phpn");
38. exit;
39. }
40.
41. /* Initialization settings */
42. @ini_set('memory_limit', '64M');
43. @ini_set('session.cache_expire', 180);
44. @ini_set('session.use_trans_sid', 0) ;
45. @ini_set('session.use_cookies', 1);
46. @ini_set('session.auto_start', 0);
47. @ini_set('display_errors', 1); // Turn on error reporting.
48.
49. //Set a common import directory. Wind is .; New directory Linux is .: What is the separation.
50. if (DIRECTORY_SEPARATOR == ''){
51. @ini_set('include_path', '.;' . ROOT_PATH);
52. }
53. else
54. {
55. @ini_set( 'include_path', '.:' . ROOT_PATH);
56. }
57. //Introduce configuration files. Simple configuration.
58. require(ROOT_PATH . 'data/config.php') ;
59.
60. // Develop good habits. Whenever a constant is defined, check whether it has been defined.
61. if (defined('DEBUG_MODE') == false){
62. define('DEBUG_MODE', 0); // Defined as 0
63. }
64.
65. //Version judgment, if the version is lower than 5.1, the table $timezone is not Empty. $timezone comes from the config.php file
66. if (PHP_VERSION >= '5.1' && !empty($timezone))
67. {
68. date_default_timezone_set($timezone); // Set the universal time zone.
69. }
70.
71. //Get the current file, excluding GET;
72. $php_self = isset($_SERVER['PHP_SELF']) ? $ _SERVER['PHP_SELF'] :
$_SERVER['SCRIPT_NAME'];
73.
74. // If the user accesses a directory, the index.php default page will be added automatically.
75 . if ('/' == substr($php_self, -1)){
76. $php_self .= 'index.php';
77. }
78. // Then change the current page The path is defined as a constant, PHP_SELF; There is no domain name orientation.
79. define('PHP_SELF', $php_self);
80.
81. // Start importing files. I will analyze them one by one in the future.
82. require(ROOT_PATH . 'includes/inc_constant.php');
83. require(ROOT_PATH . 'includes/cls_ecshop.php');
84. require(ROOT_PATH . 'includes/cls_error. php');
85. require(ROOT_PATH . 'includes/lib_time.php');
86. require(ROOT_PATH . 'includes/lib_base.php');
87. require(ROOT_PATH . 'includes/lib_common.php');
88. require(ROOT_PATH . 'includes/lib_main.php');
89. require(ROOT_PATH . 'includes/lib_insert.php');
90. require(ROOT_PATH . 'includes/lib_goods.php');
91. require(ROOT_PATH . 'includes/lib_article.php');
92.
93. /* 对用户传入的变量进行转义操作。*/ //通用转义方法. 没discuz优化.
94. if (!get_magic_quotes_gpc())
95. {
96. if (!empty($_GET))
97. {
98. $_GET = addslashes_deep($_GET);
99. }
100. if (!empty($_POST))
101. {
102. $_POST = addslashes_deep($_POST);
103. }
104.
105. $_COOKIE = addslashes_deep($_COOKIE);
106. $_REQUEST = addslashes_deep($_REQUEST);
107. }
108.
109. /* 创建 ECSHOP 对象 */
110. $ecs = new ECS($db_name, $prefix);
111.
112. //定义数据目录及图片目录.
113. define('DATA_DIR', $ecs->data_dir());
114. define('IMAGE_DIR', $ecs->image_dir());
115.
116. /* 初始化数据库类 */
117. require(ROOT_PATH . 'includes/cls_mysql.php');
118. $db = new cls_mysql($db_host, $db_user, $db_pass, $db_name);
119. // 设置不充许缓存的表, 比如用户动作,栏目.
120. $db->set_disable_cache_tables(array($ecs->table('sessions'), $ecs->table('sessions_data'),
$ecs->table('cart')));
121. $db_host = $db_user = $db_pass = $db_name = NULL;
122.
123. /* 创建错误处理对象 */
124. $err = new ecs_error('message.dwt');
125.
126. /* 载入系统参数 */
127. $_CFG = load_config();
128.
129. /* 载入语言文件 */
130. require(ROOT_PATH . 'languages/' . $_CFG['lang'] . '/common.php');
131. if ($_CFG['shop_closed'] == 1)
132. {
133. /* 商店关闭了,输出关闭的消息 */
134. header('Content-type: text/html; charset='.EC_CHARSET);
135.
136. die('
' . $_LANG['shop_closed'] .
'
' . $_CFG['close_comment'] . '