天天看點

zencart全解析(一)

Index.php

1. Load application_top.php - see {@tutorial initsystem}

2. Set main language directory based on $_SESSION['language']

3. Load all *header_php.php files from includes/modules/pages/PAGE_NAME/

4. Load html_header.php (this is a common template file)

5. Load main_template_vars.php (this is a common template file)

6. Load on_load scripts (page based and site wide)

7. Load tpl_main_page.php (this is a common template file)

8. Load application_bottom.php

require('includes/application_top.php');   //Load common library stuff

application_top.php

1. application_top.php Common actions carried out at the start of each page invocation.

2. Initializes common classes & methods. Controlled by an array which describes

3. the elements to be initialised and the order in which that happens.

First

inoculate against hack attempts which waste CPU cycles,預防黑客試圖浪費cpu周期.

Note:

if (isset($_REQUEST['GLOBALS']) OR isset($_FILES['GLOBALS'])) {

     exit('Request tainting attempted.');

}

因為如果register_globals打開的話, 用戶端送出的資料中含有GLOBALS變量名, 就會覆寫伺服器上的$GLOBALS變量. 是以這段代碼, 就是判斷, 如果送出的資料中有GLOBALS變量名, 就終止程式.

unset()是用來銷毀變量的

ini_set

Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

1.ini_set函數是設定選項中的值,在執行函數後生效,腳本結束的時候,這個設定也失效。ini_set 用于更改配置檔案的配制,次更改僅用于此腳本的執行。不是所有的選項都能被改函數設定的。

2.ini_get是ini_set的姐妹函數,

ini_set是改變php.ini裡的設定,ini_get是擷取php.ini裡的環境變量的值.

@ini_set("arg_separator.output","&");

PHP 所産生的 URL 中來分隔參數的分隔符。

include('includes/local/configure.php');   // Set the local configuration parameters - mainly for developers  (檔案不存在)

define('DEBUG_AUTOLOAD', false);// boolean if true the autoloader scripts will be parsed and their output shown. For debugging purposes only.

error_reporting(0)

就是系統或應用程式出錯時彈出的 錯誤報告,程式設計人員根據這個報告的内容可以判斷是哪一段程式代碼出問題了。      

turn off magic-quotes support, for both runtime and sybase, as both will cause problems if enabled

function_exists('set_magic_quotes_runtime')  

set_magic_quotes_runtime(0);

if (@ini_get('magic_quotes_sybase') != 0) @ini_set('magic_quotes_sybase', 0);

if    file_exists('includes/configure.php')

include('includes/configure.php');

NOTE: This file is similar, but DIFFERENT from the "admin" version of configure.php.

The 2 files should be kept separate and not used to overwrite each other.  

Define the webserver and path parameters

DIR_WS_* = Webserver directories (virtual/URL)

// * DIR_FS_* = Filesystem directories (local/physical)

the following path is a COMPLETE path to your Zen Cart files. eg: /var/www/vhost/accountname/public_html/store/

define our database connection

for STORE_SESSIONS, use 'db' for best support, or '' for file-based storage

// The next 2 "defines" are for SQL cache support.

  // For SQL_CACHE_METHOD, you can select from:  none, database, or file

  // If you choose "file", then you need to set the DIR_FS_SQL_CACHE to a directory where your apache

  // or webserver user has write privileges (chmod 666 or 777). We recommend using the "cache" folder inside the Zen Cart folder

Else  configure.php  not found

includes/templates/template_default/templates/tpl_zc_install_suggested_default.php

This page is auto-displayed if the configure.php file cannot be read properly. It is intended simply to recommend clicking on the zc_install link to begin installation.

Click here  zc_install/index.php  進入安裝程式

Ensure that the include_path can handle relative paths, before we try to load any files

strstr() 函數搜尋一個字元串在另一個字元串中的第一次出現。

該函數傳回字元串的其餘部分(從比對點)。如果未找到所搜尋的字元串,則傳回 false。

PHP中的預定義常量

再補充幾個内置的常量,

(1) DIRECTORY_SEPARATOR :路徑分隔符,linux上就是’/ ’    windows上是’/ ’

(2) PATH_SEPARATOR :include 多個路徑使用,在win下,當你要include多個路徑的話,你要用”; ” 隔開,但在linux下就使用”: ”隔開的。

這2個常量的使用能夠避免不同平台的相容性問題。  

PHP配置函數ini_get()相信很多人都使過,就是擷取配置檔案中某一個選項的值,如果是true值就傳回1,如果是false值就傳回0,字元串就傳回字元串。

比如手冊中的例子:

<?php

echo 'display_errors = ' . ini_get('display_errors') . " "; //顯示錯誤是否打開

echo 'register_globals = ' . ini_get('register_globals') . " "; //全局變量是否打開

echo 'post_max_size = ' . ini_get('post_max_size') . " "; //最多能送出的檔案大小

echo 'post_max_size+1 = ' . (ini_get('post_max_size')+1) . " ";

?>

require('includes/application_top.php');    zc_install/includes/application_top.php

Set the installer configuration parameters

include('includes/installer_params.php');

is_writable() 函數判斷指定的檔案是否可寫。

$session_save_path   d:/wamp/tmp

set the level of error reporting 

error_reporting

Timezone detection

ini_get('date.timezone')

check settings for, and then turn off magic-quotes support, for both runtime and sybase, as both will cause problems if enabled

boolean used to see if we are in the admin script, obviously set to false here.

if (!defined('IS_ADMIN_FLAG')) define('IS_ADMIN_FLAG', false);

define the project version

require('version.php');

set php_self in the local scope

繼續閱讀