搜尋
首頁後端開發php教程uploadinstallincludesauto_init.php源码分析

  1 <?php  2   3 /**  4  * ECSHOP 首页文件  5  * ============================================================================  6  * * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。  7  * 网站地址: http://www.ecshop.com;  8  * ----------------------------------------------------------------------------  9  * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和 10  * 使用;不允许对程序代码以任何形式任何目的的再发布。 11  * ============================================================================ 12  * $Author: liubo $ 13  * $Id: index.php 17217 2011-01-19 06:29:08Z liubo $ 14 */ 15  16 define('IN_ECS', true); 17  18 require(dirname(__FILE__) . '/includes/init.php'); 19  20 if ((DEBUG_MODE & 2) != 2) 21 { 22     $smarty->caching = true; 23 } 24 $ua = strtolower($_SERVER['HTTP_USER_AGENT']); 25  26 $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i"; 27  28 if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')) 29 { 30     $Loaction = 'mobile/'; 31  32     if (!empty($Loaction)) 33     { 34         ecs_header("Location: $Loaction\n"); 35  36         exit; 37     } 38  39 } 40 /*------------------------------------------------------ */ 41 //-- Shopex系统地址转换 42 /*------------------------------------------------------ */ 43 if (!empty($_GET['gOo'])) 44 { 45     if (!empty($_GET['gcat'])) 46     { 47         /* 商品分类。*/ 48         $Loaction = 'category.php?id=' . $_GET['gcat']; 49     } 50     elseif (!empty($_GET['acat'])) 51     { 52         /* 文章分类。*/ 53         $Loaction = 'article_cat.php?id=' . $_GET['acat']; 54     } 55     elseif (!empty($_GET['goodsid'])) 56     { 57         /* 商品详情。*/ 58         $Loaction = 'goods.php?id=' . $_GET['goodsid']; 59     } 60     elseif (!empty($_GET['articleid'])) 61     { 62         /* 文章详情。*/ 63         $Loaction = 'article.php?id=' . $_GET['articleid']; 64     } 65  66     if (!empty($Loaction)) 67     { 68         ecs_header("Location: $Loaction\n"); 69  70         exit; 71     } 72 } 73  74 //判断是否有ajax请求 75 $act = !empty($_GET['act']) ? $_GET['act'] : ''; 76 if ($act == 'cat_rec') 77 { 78     $rec_array = array(1 => 'best', 2 => 'new', 3 => 'hot'); 79     $rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1'; 80     $cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0'; 81     include_once('includes/cls_json.php'); 82     $json = new JSON; 83     $result   = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id); 84  85     $children = get_children($cat_id); 86     $smarty->assign($rec_array[$rec_type] . '_goods',      get_category_recommend_goods($rec_array[$rec_type], $children));    // 推荐商品 87     $smarty->assign('cat_rec_sign', 1); 88     $result['content'] = $smarty->fetch('library/recommend_' . $rec_array[$rec_type] . '.lbi'); 89     die($json->encode($result)); 90 } 91  92 /*------------------------------------------------------ */ 93 //-- 判断是否存在缓存,如果存在则调用缓存,反之读取相应内容 94 /*------------------------------------------------------ */ 95 /* 缓存编号 */ 96 $cache_id = sprintf('%X', crc32($_SESSION['user_rank'] . '-' . $_CFG['lang'])); 97  98 if (!$smarty->is_cached('index.dwt', $cache_id)) 99 {100     assign_template();101 102     $position = assign_ur_here();103     $smarty->assign('page_title',      $position['title']);    // 页面标题104     $smarty->assign('ur_here',         $position['ur_here']);  // 当前位置105 106     /* meta information */107     $smarty->assign('keywords',        htmlspecialchars($_CFG['shop_keywords']));108     $smarty->assign('description',     htmlspecialchars($_CFG['shop_desc']));109     $smarty->assign('flash_theme',     $_CFG['flash_theme']);  // Flash轮播图片模板110 111     $smarty->assign('feed_url',        ($_CFG['rewrite'] == 1) ? 'feed.xml' : 'feed.php'); // RSS URL112 113     $smarty->assign('categories',      get_categories_tree()); // 分类树114     $smarty->assign('helps',           get_shop_help());       // 网店帮助115     $smarty->assign('top_goods',       get_top10());           // 销售排行116 117     $smarty->assign('best_goods',      get_recommend_goods('best'));    // 推荐商品118     $smarty->assign('new_goods',       get_recommend_goods('new'));     // 最新商品119     $smarty->assign('hot_goods',       get_recommend_goods('hot'));     // 热点文章120     $smarty->assign('promotion_goods', get_promote_goods()); // 特价商品121     $smarty->assign('brand_list',      get_brands());122     $smarty->assign('promotion_info',  get_promotion_info()); // 增加一个动态显示所有促销信息的标签栏123 124     $smarty->assign('invoice_list',    index_get_invoice_query());  // 发货查询125     $smarty->assign('new_articles',    index_get_new_articles());   // 最新文章126     $smarty->assign('group_buy_goods', index_get_group_buy());      // 团购商品127     $smarty->assign('auction_list',    index_get_auction());        // 拍卖活动128     $smarty->assign('shop_notice',     $_CFG['shop_notice']);       // 商店公告129 130     /* 首页主广告设置 */131     $smarty->assign('index_ad',     $_CFG['index_ad']);132     if ($_CFG['index_ad'] == 'cus')133     {134         $sql = 'SELECT ad_type, content, url FROM ' . $ecs->table("ad_custom") . ' WHERE ad_status = 1';135         $ad = $db->getRow($sql, true);136         $smarty->assign('ad', $ad);137     }138 139     /* links */140     $links = index_get_links();141     $smarty->assign('img_links',       $links['img']);142     $smarty->assign('txt_links',       $links['txt']);143     $smarty->assign('data_dir',        DATA_DIR);       // 数据目录144 145     /* 首页推荐分类 */146     $cat_recommend_res = $db->getAll("SELECT c.cat_id, c.cat_name, cr.recommend_type FROM " . $ecs->table("cat_recommend") . " AS cr INNER JOIN " . $ecs->table("category") . " AS c ON cr.cat_id=c.cat_id");147     if (!empty($cat_recommend_res))148     {149         $cat_rec_array = array();150         foreach($cat_recommend_res as $cat_recommend_data)151         {152             $cat_rec[$cat_recommend_data['recommend_type']][] = array('cat_id' => $cat_recommend_data['cat_id'], 'cat_name' => $cat_recommend_data['cat_name']);153         }154         $smarty->assign('cat_rec', $cat_rec);155     }156 157     /* 页面中的动态内容 */158     assign_dynamic('index');159 }160 161 $smarty->display('index.dwt', $cache_id);162 163 /*------------------------------------------------------ */164 //-- PRIVATE FUNCTIONS165 /*------------------------------------------------------ */166 167 /**168  * 调用发货单查询169  *170  * @access  private171  * @return  array172  */173 function index_get_invoice_query()174 {175     $sql = 'SELECT o.order_sn, o.invoice_no, s.shipping_code FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o' .176             ' LEFT JOIN ' . $GLOBALS['ecs']->table('shipping') . ' AS s ON s.shipping_id = o.shipping_id' .177             " WHERE invoice_no > '' AND shipping_status = " . SS_SHIPPED .178             ' ORDER BY shipping_time DESC LIMIT 10';179     $all = $GLOBALS['db']->getAll($sql);180 181     foreach ($all AS $key => $row)182     {183         $plugin = ROOT_PATH . 'includes/modules/shipping/' . $row['shipping_code'] . '.php';184 185         if (file_exists($plugin))186         {187             include_once($plugin);188 189             $shipping = new $row['shipping_code'];190             $all[$key]['invoice_no'] = $shipping->query((string)$row['invoice_no']);191         }192     }193 194     clearstatcache();195 196     return $all;197 }198 199 /**200  * 获得最新的文章列表。201  *202  * @access  private203  * @return  array204  */205 function index_get_new_articles()206 {207     $sql = 'SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id, ac.cat_name ' .208             ' FROM ' . $GLOBALS['ecs']->table('article') . ' AS a, ' .209                 $GLOBALS['ecs']->table('article_cat') . ' AS ac' .210             ' WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1' .211             ' ORDER BY a.article_type DESC, a.add_time DESC LIMIT ' . $GLOBALS['_CFG']['article_number'];212     $res = $GLOBALS['db']->getAll($sql);213 214     $arr = array();215     foreach ($res AS $idx => $row)216     {217         $arr[$idx]['id']          = $row['article_id'];218         $arr[$idx]['title']       = $row['title'];219         $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?220                                         sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];221         $arr[$idx]['cat_name']    = $row['cat_name'];222         $arr[$idx]['add_time']    = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);223         $arr[$idx]['url']         = $row['open_type'] != 1 ?224                                         build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);225         $arr[$idx]['cat_url']     = build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']);226     }227 228     return $arr;229 }230 231 /**232  * 获得最新的团购活动233  *234  * @access  private235  * @return  array236  */237 function index_get_group_buy()238 {239     $time = gmtime();240     $limit = get_library_number('group_buy', 'index');241 242     $group_buy_list = array();243     if ($limit > 0)244     {245         $sql = 'SELECT gb.act_id AS group_buy_id, gb.goods_id, gb.ext_info, gb.goods_name, g.goods_thumb, g.goods_img ' .246                 'FROM ' . $GLOBALS['ecs']->table('goods_activity') . ' AS gb, ' .247                     $GLOBALS['ecs']->table('goods') . ' AS g ' .248                 "WHERE gb.act_type = '" . GAT_GROUP_BUY . "' " .249                 "AND g.goods_id = gb.goods_id " .250                 "AND gb.start_time <= '" . $time . "' " .251                 "AND gb.end_time >= '" . $time . "' " .252                 "AND g.is_delete = 0 " .253                 "ORDER BY gb.act_id DESC " .254                 "LIMIT $limit" ;255         $res = $GLOBALS['db']->query($sql);256 257         while ($row = $GLOBALS['db']->fetchRow($res))258         {259             /* 如果缩略图为空,使用默认图片 */260             $row['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);261             $row['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);262 263             /* 根据价格阶梯,计算最低价 */264             $ext_info = unserialize($row['ext_info']);265             $price_ladder = $ext_info['price_ladder'];266             if (!is_array($price_ladder) || empty($price_ladder))267             {268                 $row['last_price'] = price_format(0);269             }270             else271             {272                 foreach ($price_ladder AS $amount_price)273                 {274                     $price_ladder[$amount_price['amount']] = $amount_price['price'];275                 }276             }277             ksort($price_ladder);278             $row['last_price'] = price_format(end($price_ladder));279             $row['url'] = build_uri('group_buy', array('gbid' => $row['group_buy_id']));280             $row['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?281                                            sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];282             $row['short_style_name']   = add_style($row['short_name'],'');283             $group_buy_list[] = $row;284         }285     }286 287     return $group_buy_list;288 }289 290 /**291  * 取得拍卖活动列表292  * @return  array293  */294 function index_get_auction()295 {296     $now = gmtime();297     $limit = get_library_number('auction', 'index');298     $sql = "SELECT a.act_id, a.goods_id, a.goods_name, a.ext_info, g.goods_thumb ".299             "FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS a," .300                       $GLOBALS['ecs']->table('goods') . " AS g" .301             " WHERE a.goods_id = g.goods_id" .302             " AND a.act_type = '" . GAT_AUCTION . "'" .303             " AND a.is_finished = 0" .304             " AND a.start_time <= '$now'" .305             " AND a.end_time >= '$now'" .306             " AND g.is_delete = 0" .307             " ORDER BY a.start_time DESC" .308             " LIMIT $limit";309     $res = $GLOBALS['db']->query($sql);310 311     $list = array();312     while ($row = $GLOBALS['db']->fetchRow($res))313     {314         $ext_info = unserialize($row['ext_info']);315         $arr = array_merge($row, $ext_info);316         $arr['formated_start_price'] = price_format($arr['start_price']);317         $arr['formated_end_price'] = price_format($arr['end_price']);318         $arr['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);319         $arr['url'] = build_uri('auction', array('auid' => $arr['act_id']));320         $arr['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?321                                            sub_str($arr['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr['goods_name'];322         $arr['short_style_name']   = add_style($arr['short_name'],'');323         $list[] = $arr;324     }325 326     return $list;327 }328 329 /**330  * 获得所有的友情链接331  *332  * @access  private333  * @return  array334  */335 function index_get_links()336 {337     $sql = 'SELECT link_logo, link_name, link_url FROM ' . $GLOBALS['ecs']->table('friend_link') . ' ORDER BY show_order';338     $res = $GLOBALS['db']->getAll($sql);339 340     $links['img'] = $links['txt'] = array();341 342     foreach ($res AS $row)343     {344         if (!empty($row['link_logo']))345         {346             $links['img'][] = array('name' => $row['link_name'],347                                     'url'  => $row['link_url'],348                                     'logo' => $row['link_logo']);349         }350         else351         {352             $links['txt'][] = array('name' => $row['link_name'],353                                     'url'  => $row['link_url']);354         }355     }356 357     return $links;358 }359 360 ?>

调用结构层级

  • \upload\index.php
  • \upload\includes\init.php
  • \upload\install\index.php
  • \upload\install\auto_index.php
  • \upload\install\includes\auto_init.php
  • @ini_set('display_errors', 1);  //设置显示错误

    error_reporting(E_ALL ^ E_NOTICE);  //报告所有的错误、通知,其中通知是脚本发现的可能是错误的地方

     

    clearstatcache();  //清除缓存

     

    define('ROOT_PATH', str_replace('install/includes/auto_init.php', '', str_replace('\\', '/', __FILE__)));  //定义常量'ROOT_PATH'为网站根目录upload/

     if (isset($_SERVER['PHP_SELF']))  //定义常量'PHP_SELF'为,$_SERVER['PHP_SELF'](当前执行脚本的文件名)或$_SERVER['SCRIPT_NAME'](当前执行脚本所在文件夹的路径)

    {

        define('PHP_SELF', $_SERVER['PHP_SELF']);

    }

    else

    {

        define('PHP_SELF', $_SERVER['SCRIPT_NAME']);

    }  

     

    define('EC_CHARSET','utf-8');  //定义常量'EC_CHARSET'和'EC_DB_CHARSET'为UTF8

    define('EC_DB_CHARSET','utf8');

     

    require(ROOT_PATH . 'includes/lib_base.php');  //引用基础函数库,公用函数库,时间函数库,方便之后调用其中的函数

    require(ROOT_PATH . 'includes/lib_common.php');

    require(ROOT_PATH . 'includes/lib_time.php');

     

    require(ROOT_PATH . 'includes/cls_error.php');  //生成一个错误类对象,模板为message.dwt,此处并未导入dwt文件,只是给类成员对象$_template赋值

    $err = new ecs_error('message.dwt');

     

    require(ROOT_PATH . 'install/includes/cls_template.php');  //生成一个模板类对象,并给类成员对象路径$path赋值

    $smarty = new template(ROOT_PATH . 'install/templates/');

     

    require(ROOT_PATH . 'install/includes/lib_auto_installer.php');  //调用lib_auto_installer.php实际上什么也没做,lib_auto_installer.php提供了一系列库函数以供调用

     

    header('Content-type: text/html; charset='.EC_CHARSET);  //告诉浏览器文本类型,编码格式,其中EC_CHARSET在前面定义过,值为'utf-8'。

    @set_time_limit(360);  //设定脚本的最长执行时间为360秒,如果超过了时间限制,程序结束

    总结一下:

    这个php为自动安装程序做了初始化工作,包括生成一个错误类ecs_error对象(执行构造函数将公有成员变量$_template值设为‘message.dwt’),生成一个模板类template对象(执行构造函数将公有成员变量$path值设为'/upload/install/templates/';告诉浏览器文本类型为text/html,编码格式utf8;设定脚本最长执行时间为360秒。

    对于最后一条语句@set_time_limit(360)我有一些疑问想和大家分享一下。

    set_time_limit函数实际上和修改php.ini中的max_execution_time可以起到一样的效果。这里说设定脚本最长执行时间为360秒,最初看到这条语句我陷入了一个误区:由于从顶层的index.php到这个php是一路require过来,并且在执行时require语句会被它所包含的文件直接替换,那么这个360秒到底是限制哪一个php的的执行时间。就在我百思不得其解时,看到了脚本这个词,然后忽然想到这个函数不是用来限制php文件的执行时间,php文件也不是脚本文件,这个函数是用来限制ecshop中用到的js之类脚本的执行时间,原谅我没文化,在此罗嗦了一大堆。

    陳述
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
    簡單地說明PHP會話的概念。簡單地說明PHP會話的概念。Apr 26, 2025 am 12:09 AM

    phpsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIdStoredInAcookie.here'showtomanageThemeffectionaly:1)startAsessionWithSessionWwithSession_start()和stordoredAtain $ _session.2)

    您如何循環中存儲在PHP會話中的所有值?您如何循環中存儲在PHP會話中的所有值?Apr 26, 2025 am 12:06 AM

    在PHP中,遍歷會話數據可以通過以下步驟實現:1.使用session_start()啟動會話。 2.通過foreach循環遍歷$_SESSION數組中的所有鍵值對。 3.處理複雜數據結構時,使用is_array()或is_object()函數,並用print_r()輸出詳細信息。 4.優化遍歷時,可採用分頁處理,避免一次性處理大量數據。這將幫助你在實際項目中更有效地管理和使用PHP會話數據。

    說明如何使用會話進行用戶身份驗證。說明如何使用會話進行用戶身份驗證。Apr 26, 2025 am 12:04 AM

    會話通過服務器端的狀態管理機制實現用戶認證。 1)會話創建並生成唯一ID,2)ID通過cookies傳遞,3)服務器存儲並通過ID訪問會話數據,4)實現用戶認證和狀態管理,提升應用安全性和用戶體驗。

    舉一個如何在PHP會話中存儲用戶名的示例。舉一個如何在PHP會話中存儲用戶名的示例。Apr 26, 2025 am 12:03 AM

    Tostoreauser'snameinaPHPsession,startthesessionwithsession_start(),thenassignthenameto$_SESSION['username'].1)Usesession_start()toinitializethesession.2)Assigntheuser'snameto$_SESSION['username'].Thisallowsyoutoaccessthenameacrossmultiplepages,enhanc

    哪些常見問題會導致PHP會話失敗?哪些常見問題會導致PHP會話失敗?Apr 25, 2025 am 12:16 AM

    PHPSession失效的原因包括配置錯誤、Cookie問題和Session過期。 1.配置錯誤:檢查並設置正確的session.save_path。 2.Cookie問題:確保Cookie設置正確。 3.Session過期:調整session.gc_maxlifetime值以延長會話時間。

    您如何在PHP中調試與會話相關的問題?您如何在PHP中調試與會話相關的問題?Apr 25, 2025 am 12:12 AM

    在PHP中調試會話問題的方法包括:1.檢查會話是否正確啟動;2.驗證會話ID的傳遞;3.檢查會話數據的存儲和讀取;4.查看服務器配置。通過輸出會話ID和數據、查看會話文件內容等方法,可以有效診斷和解決會話相關的問題。

    如果session_start()被多次調用會發生什麼?如果session_start()被多次調用會發生什麼?Apr 25, 2025 am 12:06 AM

    多次調用session_start()會導致警告信息和可能的數據覆蓋。 1)PHP會發出警告,提示session已啟動。 2)可能導致session數據意外覆蓋。 3)使用session_status()檢查session狀態,避免重複調用。

    您如何在PHP中配置會話壽命?您如何在PHP中配置會話壽命?Apr 25, 2025 am 12:05 AM

    在PHP中配置會話生命週期可以通過設置session.gc_maxlifetime和session.cookie_lifetime來實現。 1)session.gc_maxlifetime控制服務器端會話數據的存活時間,2)session.cookie_lifetime控制客戶端cookie的生命週期,設置為0時cookie在瀏覽器關閉時過期。

    See all articles

    熱AI工具

    Undresser.AI Undress

    Undresser.AI Undress

    人工智慧驅動的應用程序,用於創建逼真的裸體照片

    AI Clothes Remover

    AI Clothes Remover

    用於從照片中去除衣服的線上人工智慧工具。

    Undress AI Tool

    Undress AI Tool

    免費脫衣圖片

    Clothoff.io

    Clothoff.io

    AI脫衣器

    Video Face Swap

    Video Face Swap

    使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

    熱工具

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

    SublimeText3 Mac版

    SublimeText3 Mac版

    神級程式碼編輯軟體(SublimeText3)

    DVWA

    DVWA

    Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

    EditPlus 中文破解版

    EditPlus 中文破解版

    體積小,語法高亮,不支援程式碼提示功能

    VSCode Windows 64位元 下載

    VSCode Windows 64位元 下載

    微軟推出的免費、功能強大的一款IDE編輯器