转载 ECSHOP 源码分析(includes/init.php)

Code:
  1.  转载  ECSHOP 源码分析(includes/init.php) 收藏  
  2.   
  3. <?php  
  4.   
  5. /** 
  6.  * ECSHOP 前台公用文件 
  7.  * ============================================================================ 
  8.  * 版权所有 (C) 2005-2006 北京亿商互动科技发展有限公司,并保留所有权利。 
  9.  * 网站地址: http://www.ecshop.com 
  10.  * ---------------------------------------------------------------------------- 
  11.  * 这是一个免费开源的软件;这意味着您可以在不用于商业目的的前提下对程序代码 
  12.  * 进行修改、使用和再发布。 
  13.  * ============================================================================ 
  14.  * @author:     Weber Liu <weberliu@hotmail.com> 
  15.  * @version:    v2.0 
  16.  * --------------------------------------------- 
  17.  * $Author: liry $ 
  18.  * $Date: 2006-11-21 10:55:39 +0800 (星期二, 21 十一月 2006) $ 
  19.  * $Id: init.php 2804 2006-11-21 02:55:39Z liry $ 
  20. */  
  21.   
  22. define('DEBUG_MODE', false);  
  23.   
  24. if (!defined('IN_ECS'))  
  25. {  
  26. /********************************************* 
  27. die 
  28. 输出信息并中断 PHP 程序。 
  29. 语法: void die(string message); 
  30. 返回值: 无 
  31. 函数种类: PHP 系统功能 
  32. 内容说明 
  33. 本函数将送出字符串到浏览器并中断 PHP 程序 (Script)。参数 message 为欲送出的字符串。 
  34. 使用范例 
  35. 下例中,若无法打开 /etc/shadow 时,传给浏览器抱歉,无法打开: /etc/shadow。 
  36. <?php 
  37. $filename = "/etc/shadow"; 
  38. $file = @fopen($filename, 'r') 
  39.   or die("抱歉,无法?/font>}启: $filename"); 
  40. echo "本行不会执行"; 
  41. ?> 
  42. ***********************************************/  
  43.   
  44.     die("Hacking attempt");  
  45. }  
  46.   
  47. /* 设置错误提示警告。 */  
  48. if (DEBUG_MODE)  
  49. {  
  50. /****************************************************** 
  51. error_reporting 
  52. 配置错误信息回报的等级。 
  53. 语法: int error_reporting(int [level]); 
  54. 返回值: 整数 
  55. 函数种类: PHP 系统功能 
  56.  
  57. 内容说明 
  58. 本函数用来配置错误信息回报的等级,参数 level 是一个整数的位遮罩 (bitmask),见下表。 
  59. 遮罩值 表示名称 
  60. 1 E_ERROR  
  61. 2 E_WARNING  
  62. 4 E_PARSE  
  63. 8 E_NOTICE  
  64. 16 E_CORE_ERROR  
  65. 32 E_CORE_WARNING  
  66. 64 E_COMPILE_ERROR  
  67. 128 E_COMPILE_WARNING  
  68. 256 E_USER_ERROR  
  69. 512 E_USER_WARNING  
  70. 1024 E_USER_NOTICE  
  71. 2047 E_ALL  
  72. 2048 E_STRICT  
  73.  
  74. E_NOTICE 表示一般情形不记录,只有程序有错误情形时才用到,例如企图存取一个不存在的变量,或是呼叫 stat() 函数检视不存在的文件。 
  75. E_WARNING 通常都会显示出来,但不会中断程序的执行。这对除错很有效。例如:用有问题的正则表达式呼叫 ereg()。 
  76. E_ERROR 通常会显示出来,亦会中断程序执行。意即用这个遮罩无法追查到内存配置或其它的错误。 
  77. E_PARSE 从语法中解析错误。 
  78. E_CORE_ERROR 类似 E_ERROR,但不包括 PHP 核心造成的错误。 
  79. E_CORE_WARNING 类似 E_WARNING,但不包括 PHP 核心错误警告。 
  80. ******************************************************/  
  81.   
  82.     error_reporting(E_ALL);  
  83. }  
  84. else  
  85. {  
  86.     error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);  
  87. }  
  88.   
  89. /* 初始化设置 */  
  90.   
  91. /**************************************************** 
  92. ini_set 
  93. (PHP 4 , PHP 5) 
  94.  
  95. ini_set -- Sets the value of a configuration option 
  96. 设置配置文件的配置项的值 
  97. Description 
  98. string ini_set ( string varname, string newvalue) 
  99.  
  100.  
  101. *****************************************************/  
  102. @ini_set('session.auto_start',      '0');  
  103. @ini_set("session.cache_expire",    180);  
  104. @ini_set('session.use_cookies',     '1');  
  105. @ini_set('memory_limit',            '16M');  
  106.   
  107. /*预定义常量 
  108.  
  109. 名称       说明 
  110. __LINE__       文件中的当前行号。  
  111. __FILE__       文件的完整路径和文件名。  
  112. __FUNCTION__   函数名称(这是 PHP 4.3.0 新加的)。  
  113. __CLASS__      类的名称(这是 PHP 4.3.0 新加的)。  
  114. __METHOD__     类的方法名(这是 PHP 5.0.0 新加的)。 
  115.   
  116. */  
  117.   
  118. /* 取得当前ecshop所在的根目录 */  
  119. define('ROOT_PATH'str_replace('includes/init.php'''str_replace('//', '/', __FILE__)));  
  120. //die(ROOT_PATH);  
  121.   
  122. /************************************************************ 
  123. file_exists 
  124. 检查文件是否存在。 
  125. 语法: int file_exists(string filename); 
  126. 返回值: 整数 
  127. 函数种类: 文件存取 
  128. 内容说明 
  129. 本函数用来测试检查文件是否存在,返回 true 表示文件存在。返回值放在快取缓冲区中,可以参考 clearstatcache()。 
  130. *************************************************************/  
  131.   
  132. if (!file_exists(ROOT_PATH.'data/install.lock') &&  
  133.     !file_exists(ROOT_PATH.'includes/install.lock') &&  
  134.     !defined('NO_CHECK_INSTALL'))  
  135. {  
  136.     header("Location: ./install/index.php/n");  
  137.  exit;  
  138. }  
  139. /******************************************************************* 
  140. clearstatcache 
  141. 清除文件状态快取。 
  142. 语法: void clearstatcache(void); 
  143. 返回值: 无 
  144. 函数种类: 文件存取 
  145.  
  146. 内容说明 
  147. 对操作系统而言,使用 stat() 或 lstat() 二个函数是很耗资源的,尤其是当每次都要重新呼叫 stat() 及 lstat() 二个函数时, 
  148. 更是不经济的方式。因此为节省资源,PHP 系统会将文件状态放在快取内存中,以便随时使用。而本函数就是提供清除快取内存中 
  149. 文件信息的函数。受本函数影响的函数有 stat()、lstat()、file_exists()、is_writeable()、is_readable()、is_executable()、 
  150. is_file()、is_dir()、is_link()、filectime()、fileatime()、filemtime()、fileinode()、filegroup()、fileowner()、filesize()、 
  151. filetype() 及 fileperms() 等十八个。 
  152. *******************************************************************/  
  153.   
  154. clearstatcache();  
  155.   
  156. require_once(ROOT_PATH."data/config.php");  
  157.   
  158. require_once(ROOT_PATH."includes/inc_constant.php");  
  159. require_once(ROOT_PATH."includes/cls_ecshop.php");  
  160. require_once(ROOT_PATH."includes/adodb/adodb.inc.php");  
  161. require_once(ROOT_PATH."includes/lib_insert.php");  
  162. require_once(ROOT_PATH."includes/lib_common.php");  
  163. require_once(ROOT_PATH."includes/lib_main.php");  
  164. require_once(ROOT_PATH."includes/cls_smtp.php");  
  165. require_once(ROOT_PATH."includes/smarty/Smarty.class.php");  
  166. require_once(ROOT_PATH."includes/lib_goodscat.php");  
  167. require_once(ROOT_PATH."includes/cls_image.php");  
  168.   
  169. if (DEBUG_MODE)  
  170. {  
  171.     include_once(ROOT_PATH."includes/lib.debug.php");  
  172. }  
  173.   
  174. /* 初始化数据库类 */  
  175. $db = &NewADOConnection('mysql');  
  176. $db->Connect($db_host$db_user$db_pass$db_nameor die("Connect to mysql database is failed");  
  177.   
  178. /* 初始化session */  
  179. $ADODB_SESSION_DRIVER           ='mysql';  
  180. $ADODB_SESSION_CONNECT          = $db_host;     
  181. $ADODB_SESSION_USER             = $db_user;    
  182. $ADODB_SESSION_PWD              = $db_pass;     
  183. $ADODB_SESSION_DB               = $db_name;       
  184. $ADODB_SESSION_TBL              = $prefix . 'sessions';  
  185. $ADODB_SESSION_RELATED_TBL      = $prefix . 'cart';  
  186. require_once(ROOT_PATH.'includes/adodb/session/adodb-session.php');     
  187. adodb_sess_open(false,false,false);     
  188.   
  189. header("Cache-control: private");  
  190. header("content-type:text/html; charset=utf-8");  
  191.   
  192. session_name('ECS_ID');  
  193. session_start();  
  194.   
  195. define('SESS_ID',   session_id());  
  196.   
  197. /* 
  198. get_magic_quotes_gpc 
  199. 取得 PHP 环境变量 magic_quotes_gpc 的值。 
  200. 语法: long get_magic_quotes_gpc(void); 
  201. 返回值: 长整数 
  202. 函数种类: PHP 系统功能 
  203. 内容说明 
  204. 本函数取得 PHP 环境配置的变量 magic_quotes_gpc 
  205. (GPC, Get/Post/Cookie) 值。返回 0 表示关闭本功能; 
  206. 返回 1 表示本功能打开。当 magic_quotes_gpc 打开时 
  207. ,所有的 ' (单引号), " (双引号), / (反斜线) and 
  208. 空字符会自动转为含有反斜线的溢出字符。 
  209. */  
  210.   
  211. /* 对用户传入的变量进行AddAlash操作。*/  
  212. if (!get_magic_quotes_gpc()) {  
  213.     function addslashes_deep($value)  
  214.     {  
  215.   
  216. /* 
  217.      AddSlashes  字符串加入斜线。 
  218.                     语法: string addslashes(string str); 
  219.                     返回值: 字符串 
  220.                     函数种类: 资料处理 
  221.                     内容说明 
  222.                     本函数使需要让数据库处理的字符串,引号的部份加上斜线, 
  223.      以供数据库查询 (query) 能顺利运作。这些会被改的字符包 
  224.      括单引号 (')、双引号 (")、反斜线 backslash (/) 以及空 
  225.      字符 NUL (the null byte)。 
  226.  
  227. array_map --  将回调函数作用到给定数组的单元上 
  228. 说明 
  229. array array_map ( mixed callback, array arr1 [, array ...] ) 
  230. array_map() 返回一个数组,该数组包含了 arr1 中的所有单元经过 callback 作用过之后的单元。 
  231. callback 接受的参数数目应该和传递给 array_map() 函数的数组数目一致。 
  232. 例子 1. array_map() 例子 
  233. <?php 
  234. function cube($n) { 
  235.     return $n*$n*$n; 
  236. } 
  237. $a = array(1, 2, 3, 4, 5); 
  238. $b = array_map("cube", $a); 
  239. print_r($b); 
  240. ?>  
  241. 这使得 $b 成为: 
  242. Array 
  243. ( 
  244.     [0] => 1 
  245.     [1] => 8 
  246.     [2] => 27 
  247.     [3] => 64 
  248.     [4] => 125 
  249. ) 
  250.   
  251.      */  
  252.   
  253.         $value = is_array($value) ?  
  254.                     array_map('addslashes_deep'$value) :  
  255.   
  256.                     addslashes($value);  
  257.   
  258.         return $value;  
  259.     }  
  260.   
  261.     $_POST      = array_map('addslashes_deep'$_POST);  
  262.     $_GET       = array_map('addslashes_deep'$_GET);  
  263.     $_COOKIE    = array_map('addslashes_deep'$_COOKIE);  
  264.     $_REQUEST   = array_map('addslashes_deep'$_REQUEST);  
  265. }  
  266.   
  267.   
  268. /* 创建 ECSHOP 对象 */  
  269. $ecs = new ECS($db_name$prefix);  
  270.   
  271. /* 载入系统参数 */  
  272.   
  273. $_CFG = load_config();//includes/lib_common.php  
  274.   
  275. /* 载入语言文件 */  
  276. require_once(ROOT_PATH.'languages/' .$_CFG['lang']. '/common.php');  
  277.   
  278. if ($_CFG['shop_closed'] == 1)  
  279. {  
  280.     header('content-type:text/html; charset=utf-8');  
  281.     die('<div style="margin: 150px; text-align: center; font-size: 14px"><p>'$_LANG['shop_closed']. '</p><p>'$_CFG['close_comment']. '</p></div>');  
  282. }  
  283.   
  284. /* 如果有新版本,升级 */  
  285. if (!isset($_CFG['ecs_version']))  
  286. {  
  287.     $_CFG['ecs_version'] = 'v2.0.5';  
  288. }  
  289. if ($_CFG['ecs_version'] != VERSION && file_exists('upgrade'))  
  290. {  
  291.     header('content-type:text/html; charset=utf-8');  
  292.     die('<div style="margin: 150px; text-align: center; font-size: 14px"><p>'$_LANG['shop_upgrade']. '</p></div>');  
  293. }  
  294.   
  295. /* 去掉商品默认图片前面的 ../ */  
  296. $_CFG['no_picture'] = str_replace('../''./'$_CFG['no_picture']);  
  297.   
  298. /* 创建 Smarty 对象。*/  
  299. $smarty = new Smarty;  
  300.   
  301. if (!file_exists(ROOT_PATH.'templates/caches'))  
  302. {  
  303.     @mkdir(ROOT_PATH.'templates/caches');  
  304.     @chmod(ROOT_PATH.'templates/caches', 0777);  
  305. }  
  306. clearstatcache();  
  307.   
  308. $smarty->template_dir   = ROOT_PATH.'templates';  
  309. $smarty->cache_lifetime = $_CFG['cache_time'];  
  310. $smarty->cache_dir      = ROOT_PATH.'templates/caches';  
  311. $smarty->compile_dir    = ROOT_PATH.'templates/compiled';  
  312. $smarty->compile_force  = false;  
  313. $smarty->compile_check  = true;  
  314.   
  315. $smarty->register_resource("db"array("db_get_template""db_get_timestamp""db_get_secure""db_get_trusted"));  
  316.   
  317. $smarty->assign('lang',             $_LANG);  
  318. $smarty->assign('thumb_width',      $_CFG['thumb_width']);  
  319. $smarty->assign('thumb_height',     $_CFG['thumb_height']);  
  320. $smarty->assign('integral_name',    $_CFG['integral_name']);  
  321. $smarty->assign('qq',               explode(','$_CFG['qq']));  
  322. $smarty->assign('ww',               explode(','$_CFG['ww']));  
  323. $smarty->assign('ym',               explode(','$_CFG['ym']));  
  324. $smarty->assign('msn',              explode(','$_CFG['msn']));  
  325. $smarty->assign('stats_code',       $_CFG['stats_code']);  
  326. $smarty->assign('copyright',        sprintf($_LANG['copyright'], date('Y'), $_CFG['shop_name']));  
  327. $smarty->assign('shop_name',        $_CFG['shop_name']);  
  328. $smarty->assign('service_email',    $_CFG['service_email']);  
  329. $smarty->assign('service_phone',    $_CFG['service_phone']);  
  330. $smarty->assign('shop_address',     $_CFG['shop_address']);  
  331. $smarty->assign('ecs_version',      VERSION);  
  332. $smarty->assign('icp_number',       $_CFG['icp_number']);  
  333. $smarty->assign('declaration',      assign_declaration());  
  334. $smarty->assign('username',         emptyempty($_SESSION['user_name']) ? '' : $_SESSION['user_name']);  
  335.   
  336. /* 会员信息 */  
  337. $user  =& init_users();  
  338.   
  339. if (!isset($_SESSION['user_id']))  
  340. {  
  341.     /* 获取投放站点的名称 */  
  342.     $site_name = isset($_GET['from']) ? urldecode($_GET['from']) : $_LANG['self_site'];  
  343.     $from_ad   = emptyempty($_GET['id']) ? 0 : $_GET['id'];  
  344.   
  345.     $_SESSION['shopping_flow']  = 'cart';                       // 购物车的当前步骤  
  346.     $_SESSION['from_ad']        = $from_ad;                     // 用户点击的广告ID  
  347.     $_SESSION['referer']        = $site_name;                   // 用户来源  
  348.   
  349.     visit_stats();  
  350. }  
  351.   
  352. if (!isset($_SESSION['user_id']) || emptyempty($_SESSION['user_id']))  
  353. {  
  354.     if ($user->get_cookie())  
  355.     {  
  356.         // 如果会员已经登录并且还没有获得会员的帐户余额、积分以及优惠券  
  357.         if (!isset($_SESSION['user_money']) && $_SESSION['user_id'] > 0)  
  358.         {  
  359.             get_user_info();  
  360.         }  
  361.     }  
  362.     else  
  363.     {  
  364.         $_SESSION['user_id']        = 0;  
  365.         $_SESSION['user_name']      = '';  
  366.         $_SESSION['email']          = '';  
  367.         $_SESSION['user_rank']      = 0;  
  368.         $_SESSION['user_money']     = 0;  
  369.         $_SESSION['user_points']    = 0;  
  370.         $_SESSION['user_bonus']     = 0;  
  371.         $_SESSION['discount']       = 1.00;  
  372.     }  
  373.   
  374. }  
  375.   
  376. /* 判断是否支持gzip模式 */  
  377. if (PHP_OS >= '4.3' && function_exists('gzcompress') && $_CFG['enable_gzip'])  
  378. {  
  379.     ob_start("ob_gzhandler");  
  380. }  
  381. ?>  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值