zen cart — one way to override function in the folder of includes/functions

zen cart don’t have a build in way to override all functions defined in the folder of includes/functions. PHP will throw out an error of “duplicate declare is not allowed”. well, we know that zen cart have built in mechanism to  override all the files in the includes/init_includes folder. And all the files in the includes/functions folder are loaded via includes/init_includes/init_general_funcs.php. let’s take a look at the php source:

[codesyntax lang=”php”]

 * load the system wide functions
 * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details.
 * @package initSystem
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: init_general_funcs.php 2845 2006-01-13 06:49:15Z drbyte $
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
 * General Functions
require(DIR_WS_FUNCTIONS . 'functions_general.php');
 * html_output functions (href_links, input types etc)
require(DIR_WS_FUNCTIONS . 'html_output.php');
 * basic email functions
require(DIR_WS_FUNCTIONS . 'functions_email.php');
 * EZ-Pages functions
require(DIR_WS_FUNCTIONS . 'functions_ezpages.php');
 * User Defined Functions
include(DIR_WS_MODULES . 'extra_functions.php');



To override the includes/functions/functions_general.php, we need make a change of this file.so

First,make a copy of includes/init_includes/init_general_funcs.php to includes/init_includes/overrides/init_general_funcs.php

Second, alter the includes/init_includes/overrides/init_general_funcs.php as below

 * General Functions
require(DIR_WS_FUNCTIONS . 'functions_general.php');


 * General Functions
require(DIR_WS_FUNCTIONS . '/overrides/functions_general.php');

Then you can do whatever changes as you want to any functions defined in that file.

if you want to overrides all files in includes/functions folder,just like zen cart build in override mechannism,the you can replace the content of includes/init_includes/overrides/init_general_funcs.php
as below:

[codesyntax lang=”php”]

if ($za_dir = @dir(DIR_WS_INCLUDES . 'includes/functions/overrides')) {
  while ($zv_file = $za_dir->read()) {
    if (preg_match('/\.php$/', $zv_file) > 0) {
      include(DIR_WS_INCLUDES . 'includes/functions/overrides' . $zv_file);








linux — install cent os via url mirros in china

Below list some available mirrors url that can be used to do a network installation of cent os:

linux — CentOS change the name of the network interface

The network didn’t work in my new minimal CentOS install. After some try on changing both “adapter type” and mac addr,i found that with ifconfig command

> ifconfig -a

First,you need to edit the file below,find the line with your mac(the one generated by Virtulbox),change ethx to ech0,remove all other lines.
> vim /etc/udev/rules.d/70-persistent-net.rules

the name of the network become eth3.not eth0 by default.but there is only ifcfg-eth0 in /etc/sysconfig/network-scirpts/. so is it possible for me to revert the name back to eth0?yes!

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”08:00:27:07:aa:e6″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”03:00:23:24:45:e2″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth1″
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”03:00:37:27:ba:a3″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth2″
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”05:00:37:07:ab:c6″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth3″

Now, reload the udev configuration.
>  start_udev

Third,restart network service
> service network restart



Linux — how to know if php run as cgi or module

For some reason you want to know how is php working with web server like apache. if you are the people who config the server,you got the answer in your head. what if you are not? well,php have a function for this:


Per php manual,call this function will returns the type of interface between web server and PHP

[codesyntax lang=”php”]



The section below is take from the php manual:
Although not exhaustive, the possible return values include aolserver, apache, apache2filter, apache2handler, caudium, cgi (until PHP 5.3), cgi-fcgi, cli, continuity, embed, isapi, litespeed, milter, nsapi, phttpd, pi3web, roxen, thttpd, tux, and webjames.

When php run in CGI mode( or any other mode other that module mode), you can not set php config via php_value directive in the .htaccess file.

you can also take a look at the phpinfo page to decide how php is working with your webserver.

zen cart — adapt zen cart to switch template based upon parameter

well,as a zen cart developer,you may have lots of zen cart template. Don’t you bother with  zen cart installation. Though you can make a batch script to generate mass zen cart websites, it will take you a lot of disk space and make you headache while searching for a special zen cart template.

so why not keep all the zen cart template in a single zen cart website.when you need to test some special zen cart template,specify a parameter with the value of template name and zen cart will take the parameter as the current template,no bother to do zen cart admin setting once and once again.

so how? the adoption of the zen cart core code is simple,as below:

Copy includes/init_includes/init_templates.php to includes/init_includes/overrides/init_templates.php,change the code like below:

$sql = “select template_dir
where template_language = ‘” . $_SESSION[‘languages_id’] . “‘”;
$template_query = $db->Execute($sql);
if ($template_query->RecordCount() > 0) {
$template_dir = $template_query->fields[‘template_dir’];

// customized by georgezheng
if (isset($_GET[‘t’])  && $_GET[‘t’] != ” ) {
$temp = trim($_GET[‘t’]);
$_SESSION[‘t’] = $temp;
} elseif ( isset($_SESSION[‘t’]) &&  $_SESSION[‘t’] != ” ) {
$temp = $_SESSION[‘t’];
} else {
$temp = ”;

if ( $temp != ” && is_dir(DIR_WS_TEMPLATES . $temp) ) {
$template_dir = $temp;

save,then browse your zen cart website with url like this http://www.abcdomain.com/?t=temp1.zen cart will looking for the template temp1,if exists temp1 will be set as current template for this session.

linux — rsync backup withou rsync daemon

i run rsync over ssh to do daily backup with the following command,

rsync -avze ‘ssh -p5000’ [USER@]HOST:SRC… [DEST]

it works ok except that when you remove file/dir from src,it can not be mapped to DESC. To make the deletion affect to the DEST backup,you need to add the –delete option.

rsync -ave ‘ssh -p5000’ –delete user@host:src  desc


Linux – Centos 6 Obtain DHCP IP Address using console

I just install a minimal CentOS 6 in my virtualbox. then i found yum did not work due to the network setting.After google,i got this —

When doing a minimal install on Centos 6, the server is not set to use DHCP by default. Most servers use static IP addresses,

First,  edit /etc/sysconfig/network-script/ifcfg-eth0 and change ONBOOT variable to yes. Then just restart the nework service.

> vi /etc/sysconfig/network-script/ifcfg-eth0

> service network restart  OR
>/etc/init.d/network restart

you can also try to run

> dhcpclient