ecshop init.php的代码详解

    发布时间:2018-06-07

    1110

    阅读量

     在includes/init.php目录下

      因为工作原因,需要对Ecshop二次开发,顺便记录一下对ecshop源代码的一些分析:

      首先是init.php文件,这个文件在ecshop每个页面都会 调用到,习惯就先分析它:

    [代码]php代码:

    e('includes/init.php', '', str_replace('', '/', __FILE__)));//检测是否已安装if (!file_exists(ROOT_PATH . 'data/install.lock') && !file_exists(ROOT_PATH . 'includes/install.lock')    && !defined('NO_CHECK_INSTALL')){    header("Location: ./install/index.phpn");    exit;}@ini_set('memory_limit',          '64M');//ini_set设置php.ini中的设置,memory_limit设定一个脚本所能够申请到的最大内存字节数@ini_set('session.cache_expire',  180);//指定会话页面在客户端cache中的有效期限(分钟),单位为分钟。@ini_set('session.use_trans_sid', 0);//关闭自动把session id嵌入到web的URL中@ini_set('session.use_cookies',   1);//允许使用cookie在客户端保存会话ID@ini_set('session.auto_start',    0);//在客户访问任何页面时都自动初始化会话,0-禁止@ini_set('display_errors',        1);//是否显示错误if (DIRECTORY_SEPARATOR == '')//如果装在windows上(DIRECTORY_SEPARATOR路径分隔符,linux上就是’/’   windows上是’’){    @ini_set('include_path', '.;' . ROOT_PATH);//include目录为当前目录和网站根目录,windows下用';'分隔}else{    @ini_set('include_path', '.:' . ROOT_PATH);//include目录为当前目录和网站根目录,linux下用':'分隔}require(ROOT_PATH . 'data/config.php');//包含配置文件(数据库相关)if (defined('DEBUG_MODE') == false)//如果常量DEBUG_MODE没有定义则定义为0,DEBUG_MODE用于设置ecshp的使用模式{    define('DEBUG_MODE', 0);}//设定用于所有日期时间函数的默认时区if (PHP_VERSION >= '5.1' && !empty($timezone)){    date_default_timezone_set($timezone);//date_default_timezone_set 设置时区}//$_SERVER['PHP_SELF']返回当前页面,获取$_SERVER['PHP_SELF']最好用htmlspecialchars过滤一下,存在XSS漏洞$php_self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['script_NAME'];if ('/' == substr($php_self, -1))//如果是"/"结尾,则加上index.php{    $php_self .= 'index.php';}define('PHP_SELF', $php_self);//放入常量require(ROOT_PATH . 'includes/inc_constant.php');//包含预定义常量文件require(ROOT_PATH . 'includes/cls_ecshop.php');//基础类 文件require(ROOT_PATH . 'includes/cls_error.php');//错误类 文件require(ROOT_PATH . 'includes/lib_time.php');//时间函数require(ROOT_PATH . 'includes/lib_base.php');//基础函数库require(ROOT_PATH . 'includes/lib_common.php');//基础函数库require(ROOT_PATH . 'includes/lib_main.php');//公用函数库require(ROOT_PATH . 'includes/lib_insert.php');//动态内容函数库require(ROOT_PATH . 'includes/lib_goods.php');//商品相关函数库require(ROOT_PATH . 'includes/lib_article.php');//文章及文章分类相关函数库if (!get_magic_quotes_gpc()){    if (!empty($_GET))    {        $_GET  = addslashes_deep($_GET);    }    if (!empty($_POST))    {        $_POST = addslashes_deep($_POST);    }    $_cookie   = addslashes_deep($_cookie);    $_REQUEST  = addslashes_deep($_REQUEST);}$ecs = new ECS($db_name, $prefix);//参数说明:数据库名 表前缀define('DATA_DIR', $ecs->data_dir());//数据目录define('IMAGE_DIR', $ecs->image_dir());//图片目录require(ROOT_PATH . 'includes/cls_mysql.php');$db = new cls_mysql($db_host, $db_user, $db_pass, $db_name);$db->set_disable_cache_tables(array($ecs->table('sessions'), $ecs->table('sessions_data'), $ecs->table('cart')));$db_host = $db_user = $db_pass = $db_name = NULL;$err = new ecs_error('message.dwt');$_CFG = load_config(); //载入配置信息函数在lib_common.phprequire(ROOT_PATH . 'languages/' . $_CFG['lang'] . '/common.php');if ($_CFG['shop_closed'] == 1){        header('Content-type: text/html; charset='.EC_CHARSET);    die('

    ' . $_LANG['shop_closed'] . '

    ' . $_CFG['close_comment'] . '

    ');}//判断是否为搜索引擎蜘蛛 函数在lib_main.phpif (is_spider()){ if (!defined('INIT_NO_USERS')) { define('INIT_NO_USERS', true); if($_CFG['integrate_code'] == 'ucenter') { $user = & init_users(); } } $_SESSION = array(); $_SESSION['user_id'] = 0; $_SESSION['user_name'] = ''; $_SESSION['email'] = ''; $_SESSION['user_rank'] = 0; $_SESSION['discount'] = 1.00;}//非搜索引擎蜘蛛,记录sessionif (!defined('INIT_NO_USERS')){ include(ROOT_PATH . 'includes/cls_session.php'); $sess = new cls_session($db, $ecs->table('sessions'), $ecs->table('sessions_data')); define('SESS_ID', $sess->get_session_id());}//如果使用Smartyif (!defined('INIT_NO_SMARTY')){ header('Cache-control: private'); header('Content-type: text/html; charset='.EC_CHARSET); require(ROOT_PATH . 'includes/cls_template.php'); $smarty = new cls_template; $smarty->cache_lifetime = $_CFG['cache_time'];//缓存时间 $smarty->template_dir = ROOT_PATH . 'themes/' . $_CFG['template'];//模板所在 $smarty->cache_dir = ROOT_PATH . 'temp/caches';//缓存所在 $smarty->compile_dir = ROOT_PATH . 'temp/compiled';//模板编译后的文件所在 if ((DEBUG_MODE & 2) == 2)//如果常量DEBUG_MODE值为 2、3、6、7.时 { $smarty->direct_output = true; //不使用缓存直接输出 $smarty->force_compile = true; //强行编译 } else { $smarty->direct_output = false; $smarty->force_compile = false; } $smarty->assign('lang', $_LANG); $smarty->assign('ecs_charset', EC_CHARSET); if (!empty($_CFG['stylename']))//如果自己定义样式文件就用自己的 { $smarty->assign('ecs_css_path', 'themes/' . $_CFG['template'] . '/style_' . $_CFG['stylename'] . '.css'); } else { $smarty->assign('ecs_css_path', 'themes/' . $_CFG['template'] . '/style.css'); }}//非搜索引擎爬虫,记录用户信息if (!defined('INIT_NO_USERS')){ $user =& init_users(); if (!isset($_SESSION['user_id'])) { $site_name = isset($_GET['from']) ? $_GET['from'] : addslashes($_LANG['self_site']); $from_ad = !empty($_GET['ad_id']) ? intval($_GET['ad_id']) : 0; $_SESSION['from_ad'] = $from_ad; // 用户点击的广告ID $_SESSION['referer'] = stripslashes($site_name); // 用户来源 unset($site_name); if (!defined('INGORE_VISIT_STATS')) { visit_stats(); } } if (empty($_SESSION['user_id'])) { if ($user->get_cookie()) { if ($_SESSION['user_id'] > 0) { update_user_info(); } } else { $_SESSION['user_id'] = 0; $_SESSION['user_name'] = ''; $_SESSION['email'] = ''; $_SESSION['user_rank'] = 0; $_SESSION['discount'] = 1.00; if (!isset($_SESSION['login_fail'])) { $_SESSION['login_fail'] = 0; } } } if (isset($_GET['u'])) { set_affiliate(); } if (isset($smarty)) { $smarty->assign('ecs_session', $_SESSION); }}if ((DEBUG_MODE & 1) == 1)//如果常量DEBUG_MODE值为 1、3、5、7.时{ error_reporting(E_ALL);//报告全部错误}else{ error_reporting(E_ALL ^ E_NOTICE); //报告除E_NOTICE以外的所有错误}if ((DEBUG_MODE & 4) == 4)//如果常量DEBUG_MODE值为 4、5、6、7.时,调试程序{ include(ROOT_PATH . 'includes/lib.debug.php');//}if (!defined('INIT_NO_SMARTY') && gzip_enabled()){ ob_start('ob_gzhandler');//压缩后放入缓冲区}else{ ob_start();//打开缓冲区,把下面要显示的内容先缓在服务器}?>