1. ecshop init.php文件分析
2. 3.
4. /**
5. * ecshop 前台公用文件
6. *
===========================================================================
=
7. * 版权所有 2005-2008 上海商派网络科技有限公司,并保留所有权利。
8. * 网站地址: [url]http://www.ecshop.com[/url];
9. * ----------------------------------------------------------------------------
10. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
11. * 使用;不允许对程序代码以任何形式任何目的的再发布。
12. *
===========================================================================
=
13. * $author: likai $
14. * $id: init.php 16132 2009-05-31 08:59:15z likai $
15. */
16.
17. // 禁止跨域引入文件.
18. if (!defined('in_ecs')){
19. die('hacking attempt'); // 黑客企图
20. }
21.
22. // 无用代码,后期功能复盖
23. error_reporting(e_all);
24.
25. // 防止菜鸟将此变量从get post 或者新常量定义.
26. if (__file__ == ''){
27. die('fatal error code: 0');
28. }
29.
30. /* 取得当前ecshop所在的根目录 比discuz的复杂 */
31. define('root_path', str_replace('includes/init.php', '', str_replace('\', '/', __file__)));
32.
33. // 判断data目录中的install文件不存在 && include中的安装锁文件不存在 并且没有定义
no_check_install常量, 就跳转到安装页.
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. /* 初始化设置 */
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); // 开启报错.
48.
49. //设置通用的引入目录. wind 是 .; 新的目录 linux是 .: 就是以什么为分隔.
50. if (directory_separator == '\'){
51. @ini_set('include_path', '.;' . root_path);
52. }
53. else
54. {
55. @ini_set('include_path', '.:' . root_path);
56. }
57. // 引入配置文件.简单的配置.
58. require(root_path . 'data/config.php');
59.
60. // 养成良好的习惯, 凡是常量定义,都判断一下是否已经定义过.
61. if (defined('debug_mode') == false){
62. define('debug_mode', 0); // 定义为0
63. }
64.
65. //版本判断, 如果版本低于5.1 并表$timezone不为空. $timezone来自 config.php文件
66. if (php_version >= '5.1' && !empty($timezone))
67. {
68. date_default_timezone_set($timezone); // 设置通用时区.
69. }
70.
71. //获得当前文件,不包括get;
72. $php_self = isset($_server['php_self']) ? $_server['php_self'] :
$_server['script_name'];
73.
74. // 假如用户访问的是目录, 就自动添加index.php默认页.
75. if ('/' == substr($php_self, -1)){
76. $php_self .= 'index.php';
77. }
78. // 然后将当前页路径定义为常量,php_self; 没有域名导向的.
79. define('php_self', $php_self);
80.
81. // 开始引入文件了.日后再一个一个分析.
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'] . '
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号