Home Backend Development PHP Tutorial ecshop init.php file analysis_PHP tutorial

ecshop init.php file analysis_PHP tutorial

Jul 20, 2016 am 11:13 AM
ecshop php analyze document

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'] . '

');
137. }
138.
139. if (is_spider())
140. {
141. /* If it is a spider access, the default is guest mode , and not recorded in the log */
142. if (!defined('INIT_NO_USERS'))
143. {
144. define('INIT_NO_USERS', true);
145. / * After integrating UC, if it is a spider access, initialize the constants needed for UC */
146. if($_CFG['integrate_code'] == 'ucenter')
147. {
148. $user = & init_users();
149. }
150. }
151. $_SESSION = array(); $_SESSION['user_name'] = '';
154. $_SESSION['email'] = '';
155. $_SESSION['user_rank'] = 0;
156. $_SESSION[ 'discount'] = 1.00;
162. include(ROOT_PATH . 'includes/cls_session.php');
163.
164. $sess = new cls_session($db, $ecs->table('sessions'), $ ecs->table('sessions_data'));
165.
166. define('SESS_ID', $sess->get_session_id()); 🎜>169. if (!defined('INIT_NO_SMARTY'))
170. {
171. header('Cache-control: private');
172. header('Content-type: text/ html; charset='.EC_CHARSET);
173.
174. /* Create Smarty object. */
175. require(ROOT_PATH . 'includes/cls_template.php');
176. $smarty = new cls_template;
177.
178. $smarty->cache_lifetime = $_CFG ['cache_time'];
179. $smarty->template_dir = ROOT_PATH . 'themes/' . $_CFG['template'];
180. $smarty->cache_dir = ROOT_PATH . 'temp/ caches';
181. $smarty->compile_dir = ROOT_PATH . 'temp/compiled';
182.
183. // Determine whether to update.
184. if ((DEBUG_MODE & 2) == 2)
185. {
186. $smarty->direct_output = true;
187. $smarty->force_compile = true;
188. }
189. else
190. {
191. $smarty->direct_output = false;
192. $smarty->force_compile = false; >195. // Familiar smarty injection.
196. $smarty->assign('lang', $_LANG);
197. $smarty->assign('ecs_charset', EC_CHARSET);
198. // Set CSS file.
199. if (!empty($_CFG['stylename']))
200. {
201. $smarty->assign('ecs_css_path ', 'themes/' . $_CFG['template'] . '/style_' . $_CFG['stylename'] . '.css');
202. }
203. else
204 . {
205. $smarty->assign('ecs_css_path', 'themes/' . $_CFG['template'] . '/style.css');
206. }
207.
208. }
209.
210. if (!defined('INIT_NO_USERS'))
211. {
212. /* Member information */
213. $user =& init_users();
214.
215. if (!isset($_SESSION['user_id']))
216. {
217. /* Get the name of the delivery site */
218. $site_name = isset($_GET['from']) ? $_GET['from'] : addslashes($_LANG['self_site']);
219. $from_ad = !empty($ _GET['ad_id']) ? intval($_GET['ad_id']) : 0;
220.
221. $_SESSION['from_ad'] = $from_ad; // Advertising ID clicked by the user
222. $_SESSION['referer'] = stripslashes($site_name); // User source
223.
224. unset($site_name);
225.
226. if ( !defined('INGORE_VISIT_STATS'))
227. {
228. visit_stats();
229. }
230. }
231.
232. if (empty($ _SESSION['user_id']))
233. {
234. if ($user->get_cookie())
235. {
236. /* If the member has logged in and has not Get member's account balance, points and coupons */
237. if ($_SESSION['user_id'] > 0)
238. {
239. update_user_info();
240.  } 
241.  } 
242.  else 
243.  { 
244.  $_SESSION['user_id'] = 0; 
245.  $_SESSION['user_name'] = ''; 
246.  $_SESSION['email'] = ''; 
247.  $_SESSION['user_rank'] = 0; 
248.  $_SESSION['discount'] = 1.00; 
249.  if (!isset($_SESSION['login_fail'])) 
250.  { 
251.  $_SESSION['login_fail'] = 0; 
252.  } 
253.  } 
254.  } 
255.  
256.  /* 设置推荐会员  */ 
257.  if (isset($_GET['u'])) 
258.  { 
259.  set_affiliate(); 
260.  } 
261.  if (isset($smarty)) 
262.  { 
263.  $smarty->assign('ecs_session', $_SESSION); 
264.  } 
265.  } 
266.  // 修改报错级别. 
267.  if ((DEBUG_MODE & 1) == 1) 
268.  { 
269.  error_reporting(E_ALL); 
270.  } 
271.  else 
272.  { 
273.  error_reporting(E_ALL ^ E_NOTICE); 
274.  } 
275.  if ((DEBUG_MODE & 4) == 4) 
276.  { 
277.  include(ROOT_PATH . 'includes/lib.debug.php'); 
278.  } 
279.  
280.  /* 判断是否支持  Gzip 模式  */ 
281.  if (!defined('INIT_NO_SMARTY') && gzip_enabled()) 
282.  { 
283.  ob_start('ob_gzhandler'); 
284.  } 
285.  else 
286.  { 
287.  ob_start(); 
288.  } 
289.  
290.  ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440381.htmlTechArticle1. ecshop init.php文件分析 2. ?php 3. 4. /** 5. * ECSHOP 前台公用文件 6. * =========================================================================== = 7. * 版权所有...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles