Ecshop in the init.php file

Source: Internet
Author: User
Ecshop in the init.php file
Under the includes/init.php directory

For work reasons, need to ecshop two times development, by the way to record some of the Ecshop source code analysis:

The first is the init.php file, which is called on every page of Ecshop, and is used to analyze it first:

 Php/** * ECSHOP front desk public files*///prevents illegal calls to defined-to determine if a constant is defined, if it does not return falseif(!defined(' In_ecs ')){  die(' Hacking attempt ');//die-directly terminates the program and outputs} //Report All Errorserror_reporting(E_all); //If you cannot get to this fileif(__file__== ''){  die(' Fatal error code:0 ');} /*the current line number in the pre-defined constant __line__ file. The full path and file name of the __file__ file. __function__ function name (this is the new addition of PHP 4.3.0). The name of the __class__ class (this is a new addition to PHP 4.3.0). The method name of the __method__ class (this is a new addition to PHP 5.0.0). *//*get the root directory where the current store is located*/Define(' Root_path ',Str_replace(' includes/init.php ', ',Str_replace('\\', '/',__file__))); //detect if it is installedif(!file_exists(Root_path. ' Data/install.lock ') &&!file_exists(Root_path. ' Includes/install.lock ') &&!defined(' No_check_install ')){ Header("Location:./install/index.php\n"); Exit;} /*Initialize Settings*/@Ini_set(' Memory_limit ', ' 64M ');//ini_set setting settings in PHP.ini, Memory_limit sets the maximum number of bytes of memory that a script can request@Ini_set(' Session.cache_expire ', 180);//Specifies the length of time (in minutes) of the session page in the client cache, in minutes. @Ini_set(' Session.use_trans_sid ', 0);//turn off automatically embed the session ID into the URL of the Web@Ini_set(' Session.use_cookies ', 1);//allow cookie to be used to save session ID on client@Ini_set(' Session.auto_start ', 0);//automatically initialize a session when a customer accesses any page, 0-Forbidden@Ini_set(' Display_errors ', 1);//whether an error is displayedif(directory_separator = = ' \ \ ')//if installed on Windows (directory_separator path delimiter, Linux is '/' on Windows is ' \ '){    @Ini_set(' include_path ', '.; '). Root_path);//The include directory is the current directory and the Web site root directory, Windows uses '; ' Delimited} Else{    @Ini_set(' include_path ', '.: '. Root_path);//The include directory is the current directory and Web site root, and Linux is separated by ': '} require(Root_path. ' data/config.php ');//include configuration files (database related)if(defined(' debug_mode ') = =false)//defined as 0,debug_mode used to set ECSHP usage mode if the constant debug_mode is not defined{ Define(' Debug_mode ', 0);} //Set the default time zone for all datetime functionsif(php_version>= ' 5.1 ' &&!Empty($timezone) {Date_default_timezone_set ($timezone);//Date_default_timezone_set Setting the time zone} //$_server[' php_self '] return to the current page, get $_server[' php_self '] best with htmlspecialchars filter, there is an XSS vulnerability$php _self=isset($_server[' Php_self ']) ?$_server[' Php_self ']:$_server[' Script_name ']; if('/' ==substr($php _self,-1))//if "/" ends, add index.php{ $php _self. = ' index.php ';} Define(' Php_self ',$php _self);//put constantsrequire(Root_path. ' includes/inc_constant.php ');//contains predefined constant filesrequire(Root_path. ' includes/cls_ecshop.php ');//base class Filesrequire(Root_path. ' includes/cls_error.php ');//Error class filerequire(Root_path. ' includes/lib_time.php ');//Time Functionrequire(Root_path. ' includes/lib_base.php ');//Base Function Libraryrequire(Root_path. ' includes/lib_common.php ');//Base Function Libraryrequire(Root_path. ' includes/lib_main.php ');//Common Functions Libraryrequire(Root_path. ' includes/lib_insert.php ');//Dynamic content Function libraryrequire(Root_path. ' includes/lib_goods.php ');//Commodity correlation Function Libraryrequire(Root_path. ' includes/lib_article.php ');//article and article Classification correlation function library/*escapes the variable passed in by the user. */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);} /*Create a ECSHOP object*/$ecs=NewECS ($db _name,$prefix);//parameter Description: Database name table prefixDefine(' Data_dir ',$ecs->data_dir ());//Data CatalogDefine(' Image_dir ',$ecs->image_dir ());//Picture Catalogue/*initializing the Database class*/require(Root_path. ' Includes/cls_mysql.php '); $db=NewCls_mysql ($db _host,$db _user,$db _pass,$db _name); /*to set a table that does not allow caching*/$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; /*creating error Handling Objects*/$err=NewEcs_error (' message.dwt '); /*Loading System Parameters*/$_cfg= Load_config ();//load configuration information function in lib_common.php/*Loading language files*/require(Root_path. ' Languages/'.$_cfg[' Lang ']. '/common.php '); if($_cfg[' shop_closed '] = = 1){ /*The store closes, the output closes the message*/Header(' content-type:text/html; charset= '.ec_charset);  die('

' . $_lang [' shop_closed ']. '

' . $_cfg [' Close_comment ']. '

');} //Judging whether the spider function for search engines is in lib_main.phpif(Is_spider ()) {/*if it is a spider's access, then the default is Guest mode and is not recorded in the log*/if(!defined(' Init_no_users ')) { Define(' Init_no_users ',true); /*after consolidating UC, if it is spider access, initialize the required constants for UC*/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;} //non-search engine spider, record sessionif(!defined(' Init_no_users ')){ /*Initialize Session*/include(Root_path. ' Includes/cls_session.php '); $sess=NewCls_session ($db,$ecs->table (' Sessions '),$ecs->table (' Sessions_data ')); Define(' sess_id ',$sess-get_session_id ());} //If you use Smartyif(!defined(' Init_no_smarty ')){ Header(' Cache-control:private '); Header(' content-type:text/html; charset= '.ec_charset); /*creates a Smarty object. */require(Root_path. ' Includes/cls_template.php '); $smarty=Newcls_template;$smarty->cache_lifetime =$_cfg[' Cache_time '];//Cache Time$smarty->template_dir = Root_path. ' Themes/'.$_cfg[' template '];//template where$smarty->cache_dir = Root_path. ' Temp/caches ';//Cache Location$smarty->compile_dir = Root_path. ' Temp/compiled ';//the file where the template was compiledif((Debug_mode & 2) = = 2)//if the constant Debug_mode value is 2, 3, 6, 7. { $smarty->direct_output =true;//do not use cache direct output$smarty->force_compile =true;//forced compilation } Else { $smarty->direct_output =false; $smarty->force_compile =false; } $smarty->assign (' Lang ',$_lang); $smarty->assign (' Ecs_charset ',ec_charset); if(!Empty($_cfg[' StyleName ']))//If you define a style file, use your own { $smarty->assign (' Ecs_css_path ', ' themes/').$_cfg[' Template ']. '/style_ '.$_cfg[' StyleName ']. '. css '); } Else { $smarty->assign (' Ecs_css_path ', ' themes/').$_cfg[' Template ']. '/style.css '); }} //non-search engine crawler, record user informationif(!defined(' Init_no_users ')){ /*member Information initialize member data lib_common.php*/$user=&init_users ();if(!isset($_session[' user_id '])) { /*get the name of the site you are running*/$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;//the ad ID that the user clicked on$_session[' referer '] =stripslashes($site _name);//User Sourceunset($site _name); if(!defined(' Ingore_visit_stats ') ) {visit_stats (); } } if(Empty($_session[' user_id '])) { if($user-Get_cookie ()) { /*if the member has logged in and has not received the member's account balance, points and coupons*/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; } } } /*set up recommended members*/if(isset($_get[' U ']) {set_affiliate (); } if(isset($smarty)) { $smarty->assign (' Ecs_session ',$_session); }} if((Debug_mode & 1) = = 1)//if the constant Debug_mode value is 1, 3, 5, 7.{ error_reporting(E_all);//Report All Errors} Else{ error_reporting(E_all^E_notice);//report all errors except E_notice} if((Debug_mode & 4) = = 4)//if the constant Debug_mode value is 4, 5, 6, 7, the debugger{ include(Root_path. ' includes/lib.debug.php ');// } /*determine if Gzip mode is supported if you set up page compression using Smarty, compression is enabled*/if(!defined(' Init_no_smarty ') &&gzip_enabled ()) { Ob_start(' Ob_gzhandler ');//compress and put into buffer} Else{ Ob_start();//Open the buffer, put the following to display the contents of the first slow on the server} /*Ob_start Correlation Function Understanding: 1, Flush: Flush the contents of the buffer, output. function format: Flush () Description: This function is often used and is highly efficient. 2, Ob_start: Open output buffer function format: void Ob_start (void) Description: When the buffer is activated, all non-file header information from the PHP program is not sent, but is saved in the internal buffer. In order to output the contents of the buffer, you can use the contents of the Ob_end_flush () or flush () output buffers. , ob_get_contents: Returns the contents of the internal buffer. Usage: string ob_get_contents (void) Description: This function returns the contents of the current buffer and returns FALSE if the output buffer is not activated. 4. Ob_get_length: Returns the length of the internal buffer. Usage: int ob_get_length (void) Description: This function returns the length in the current buffer, as in ob_get_contents if the output buffer is not active. FALSE is returned. 5. Ob_end_flush: Sends the contents of the internal buffer to the browser, and closes the output buffer. Method of Use: void Ob_end_flush (void) Description: This function sends the contents of the output buffer, if any. 6. Ob_end_clean: Delete the contents of the internal buffer and close the internal buffer use method: void Ob_end_clean (void) Description: This function does not output the contents of the internal buffer but deletes it! 7. Ob_implicit_flush: Turn absolute refresh on or off using the method: void Ob_implicit_flush ([int flag]) Description: People who have used Perl know the meaning of $|=x, this string can open/close the buffer, and ob_ The Implicit_flush function is the same as that, the default is to close the buffer, open the absolute output, each script output is sent directly to the browser, no longer need to call flush ()*/?>

The above describes the Ecshop in the init.php file in detail, including the contents of the ecshop,init.php file, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.