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);
iffile_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
Elseconfigure.phpnot 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 herezc_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
/* Our php.ini contains the following settings: display_errors = On register_globals = Off post_max_size = 8M */
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_pathd:/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