Tuesday, November 10, 2009

long number problem in php 5.2.6

I found an interesting problem with long numbers using php 5.2.6. Yah, the current version of php is 5.3 but some hosting server still using older versions.

my problem was the following:


$integer = 2304200000;
echo $integer; //outputs 2.3042E+09

$float = (float)100000; //float
echo $float; //outputs 1E+05


this gives many weird results in calculation. I have faced this problem and this bug has eaten up a lot of time.So, I am others time regarding the big number problem in php 5.2.6.

If you use number_format or sprintf then you will get the number as aspected.


$integer = 2304200000;
$int = number_format($integer, 0, '.', '');
echo $int; //outputs 2304200000 as expected

$float = (float)100000 //float;
$float = number_format($float, 2, '.', '');
echo $float; //outputs 100000.00 as expected




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Wednesday, October 14, 2009

increasing file upload size in wordpress.

I have faced a problem regarding uploading of big images in wordress. In php 5.2.5, it has change it's configuration file structure. Now it sets access level to it's directives. The levels are 7,4,2,1. And for this access control now we can't modify every configuration settings by ini_set() function in runtime.

Those that have access level 7, can be modified by ini_set() function. And some can be set using .htaccess file. And some need to have admin level access.

If you want to use .htaccess file then you need to paste the following code into you .htaccess file.


php_value upload_max_filesize 100M
php_value post_max_size 105M
php_value max_execuetion_time 300
php_value memory_limit 64M


you need to set post_max_size to larger size than upload_max_filesize, as there could be multiple upload field in a form.

Now, while you are using .htaccess file, the server may not support the directive changing command that you are trying to modify. I mean your server need to have AllowOverride property On for the specific directive that you are trying to modify. you need to contact with your hosting server support.

There is another way, you can create a php.ini file with the configuration directive that you want to change. For image uploading in wordpress, you can create the following php.ini file.


;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

upload_max_filesize = 100M;
post_max_size = 105M;
max_execution_time = 300;

;End:


you need to place it under the wp-admin folder.






List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Tuesday, September 29, 2009

Api for XML

There are various api for accessing xml documents. They are the following-

  • Stream oriented api: Simple api for xml or SAX, it is event based.
  • Tree traversal api: Dom is a tree-traversal api. DOM implementation is memory intensive, as it loads the whole xml tree before accessing data.
  • Xml data binding: which is a automated way to convert XML document.
  • Declarative transformation languages: XSLT, XQuery.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Monday, September 28, 2009

Introduction to JSON

JSON means javascript object notation. JSON is lightweight and very easy to parse.
It is not a markup language. The basis of JSON is that javascript’s object literal
is the ideal way for transmitting object oriented data across the network. Json made it easier to produce distributed object and applications. JSON does not support octal or hex characters. The character encoding of json is always Unicode. Json is the preferred way for ajax applications. A response text can be converted to javascript with eval() function. json's values can be used directly, no convertiion needed. this is the most significant reason to use json. json has no namespaces so there is no nesting and it uses context. JSON doesn't have any validator.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Sunday, September 27, 2009

Why should I use static variable?

Let’s see the difference between static and non-static variable:
Static is used for those method and variables which are accessed from other classes or functions also. If we use non-static, then we need to instantiate the class each time to use that methods or variables. Static variable has it’s scope until the script ends, whereas a non-static variable lost it’s value when it’s scope ends.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Wednesday, September 23, 2009

OOP vs procedural

OOP provides ways for extensible application. this approach removes the drawbacks of procedural paradigm. it gives first priority to data. it packs data and functions, which have access to this functions. this avoids unauthorized access to functions. So, OOP gives us ability of reuse, inheritence, access modifier.

procedural provides ways for fast, shortcut approach for programming. so, before coding we must think what we want to do. if we want a small coding to do a small job, then we must go for procedural approach. But as the requirements grew, it was seen that the programs were getting larger and larger and it became difficult to debug. So functions were introduced to reduce the size of the programs and improve readability in them. Still that was not enough. In this approach, data is getting corrupted, as many functions which are not allowed to access the function can access the functions. so, here more focus was given on functions, rather than data.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Sunday, September 20, 2009

Problem with normal and session variable having same name

If your register_globals is set to ON, then a normal variable will overwrite a session variable with the same name. In webid, I faced this problem. It's not a good practice to turn ON register_globals. So, turn it Off it will fix the problem with same variable name.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Thursday, September 17, 2009

xml vs database

XML can be used as databases. But the question is that why should I use it or why should I avoid it? XML has the properties of storage, portability, schemas. Xml is self describing means the elements, attributes tells what the data it contains. It also describes data in tree or graph structure.
Xml provides many qualities of databases.
1. Storage: Xml documents.
2. Schemas: DTDs, Xml schemas.
3. Query languages: Xpath, Xquery.
4. Programming interfaces: SAX, DOM.
And it also lacks some of the cool features of databases.
1. Security.
2. Integrity.
3. Indexes.
4. Transaction.
5. Efficient storage.
6. Multi user access.
7. Triggers.
8. Queries across multiple documents.
So, xml can be used as a database for few users, small amount of data. But for product environment where there will larger data, huge user, need data integrity, there needs databases. So, there is very little advantage to use xml as a database.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Wednesday, September 16, 2009

.htaccess intro

.htaccess files are used to modify server configuration on per-directory basis. It is used when a user doesn’t has access to modify server configuration settings. The directives in .htaccess file is applied for the current directory and subdirectories. .htaccess uses those directives that has their AllowOverride property set to not none.

If we can, we should avoid using .htaccess file mainly for the following 2 reasons –
1. When we set AllowOverride property to allow modification in .htaccess files, then the server checks every directory for .htaccess file. This hit the performance.
2. Second one is security. We are allowing users to change server configuration. So, it may become a security hole.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Tuesday, September 15, 2009

Use component as multipart document

This will use different component of a webpage as an attachment. So, components will be loaded with one http request. This will improve webpage loading time. But iphone doesn’t support this technique.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

minify js and css

We can minify javascript and css, so the loading of these files will be faster. There are two popular tools: jsmin and YUI compression. YUI compression can compress CSS files also. Minify will reduce size upto 25% of it size. We can use minify after gzip, it will reduce the size upto 5%. Minify removes redundant contents.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Reduce DNS lookups

Each DNS will be converted to IP address. Server will wait until the conversion completes. DNS lookup takes 20-100 miliseconds. The DNS is cached for later use. Firefox uses 1 min, IE uses 30 min for the dns caching. This caching is done on a special caching server. Each browser has a own DNS cache. It also stores the information on the operating systems cache.
Reducing DNS lookup cuts response time, but also reduces parallel downloading so increases response time. We can use upto 4 hostnames which will increase our speed.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Use external files for javascript and css

Using external files for javascript and css will reduce the file size without increasing the number of http requests. But we can use inline code for home page which has less page views. So, we can use caching for those pages which reuses same scripts and stylesheets.

There are some files which are common on homepage and other pages. For that case, we can load inline codes for homepage and then we can load those scripts by external files.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

CSS expressions

CSS expressions use javascripts. And the page is evaluated for scrolling or even mouse moving. We avoid expressions as they create many evaluation to the page. So, if we need to use expressions we must use one-time loading.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Put scripts at the bottom

According to the http/1.1 a page can download no more than 2 scripts at a time. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames.

Sometime, we can’t put scripts at the bottom. When the scripts load some content that will be used in the middle of the page, then we need to call the script early. We can use DEFER attribute which shows the script does not contain document.write. but firefox doesn’t support this attribute.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Loading stylesheets on top

Always include stylesheets in the head tag. This will load the page faster. Users want to see their pages faster. So, for this purposes, the loading image is getting popular. So, if we set the stylesheets in the head tag, then the images, banner, header will load faster and will give the user an impression of page loading. If we place the stylesheet at the bottom, then it may show a blank page for some time in some browser like internet explorer.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Gzip contents

Web content size can be reduced by gziping them. If we set accept-encoding to gzip or any other compression techniques, then the web server responses with the content-encoding header that tells the browser to compress the web content.
We can’t compress images and pdf files as they are already compressed. By compressing these may increase web content size.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Cache control

For caching features, we can use two techniques-
1. For static contents, we can set the expire attribute to a furthest future.
2. For dynamic contents, we can set an appropriate cache-control.
For static contents, like images, stylesheet, flash etc, can be cached in the browser for faster page load. This will reduce http request time. This will not effect for the first time the page loads, but the result will be at later page requests when the cache will be full.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Using content delivery network

Content delivery network(CDN) is a distributed service of static contents i.e. images, stylesheets, javascripts, flash etc. it will reduce http loading time drastically. There are many organization who provides this service. CDN uses many distributed servers who will store the static contents. In this case, the nearest or the shortest response time server is chosen.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Reducing HTTP request

To speed up a web page loading, our first goal will be to reduce the number of http request. The less the http request, the faster the page will be load. There are many ways to reduce http request. We can use css sprites, combined css, image maps etc. there is another technique called inline images, it uses of the form, data: mediatype;base64;data.Another way to reduce the number of http request is by having a full cache.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Minify your javascript file with jsmin

It will minify the javascript file. We minify javascript files so it will reduce page loading. JSMin first replaces carriage returns ('\r') with linefeeds ('\n'). It replaces all other control characters (including tab) with spaces. It replaces comments in the // form with linefeeds. It replaces comments in the /* */ form with spaces. There are many supported programming language available to use jsmin. I used php.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Wednesday, September 2, 2009

Affiliate program in prestashop

Prestashop 1.2 comes with a affiliate module. By this we can track affiliates. You need to set every thing manually here.
To start with affiliate program, go to the back office > stats > referrers. To add a new affiliates, click the add new button.
You need to create an affiliate account first with username and password. Under that section there is the url by which you can see the affiliate space on the front office.
With the HTTP_REFERER section, set the domain name in the include field that you want to track as your affiliate domain. We can use the keyword like ‘MySQL LIKE’ feature, for example, put ‘%google%’, this will track all the request that come from the google search engine.
With the Request_uri section, we can set the last part of the query string. Our affiliate program will track this url. For example, someone uses %aff% in the include field. So, his affiliate link will be any url of the shop that have ‘aff’ in it’s url.
Then save your changes. You can see your affiliate statistics in the front panel. It will take approximately an hour to see the changes.
See the book OpenCart 1.4 Template Design Cookbook. See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Tuesday, September 1, 2009

how to create hooks in prestashop

Creating hook is pretty easy in prestashop, add a new row with the ps_hook table in the databases. Enter the name of the hook and the id of the hook. Now, go to the php file in which you want to add the hook. Add ‘HOOK_demo’ => Module::hookExec(‘demo’) into the smarty assign variable where demo is the hook name. Then place the { HOOK_demo } in the .tpl file where you want to see the content.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

how to write a module with prestashop

Every module is load with a hook. A hook is a module holder. Prestashop has some default hooks. We will see later how to createhooks.

Ok, now lets start to make a module with prestashop. First make a folder with the modulename. Create a .tpl file with the modulename. Write the presentation code here.
Then create a .php file with the modulename. The following is a dummy class for our module.


// class name must be same with the modulename, not case sensitive.

class Fashion extends Module
{
function __construct()
{
$this->name = 'fashion'; // this is the name of the module
$this->tab = 'Blocks';
$this->version = 1.0;

parent::__construct(); // The parent construct is required for translations

$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Block Fashion');
$this->description = $this->l('Add a fashion block');
}

function install()
{
if (!parent::install())
return false;
if (!$this->registerHook('leftColumn')) // we are setting this module with the left column.
return false;
return true;
}

/**
* Returns module content
*
* @param array $params Parameters
* @return string Content
*/
// as we are setting this module on left column, we are using this hook to load our module.
function hookLeftColumn($params)
{
return $this->display(__FILE__, 'fashion.tpl');
}

}
?>




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Back office in prestashop

Back office is the prestashop admin panel. We can control the front office with it. So, we must know the features that prestashop has come up with.


Prestashop has the following section on the back office:

Catalog : use catalog to modify different properties of products.
• Category and subcategory: sort products by category. A product can be under multiple category and subcategories.
• Products: use this to add different properties of a product.
• Manufactures: manage manufactures.
• Suppliers: manage suppliers.
• Attributes : create and manage different attributes for different model of a products.
Customer: manage customers.
Orders: manage orders. You can use merchandising return and PDF invoice here.
Payments: under payment section , there are modules, taxes, currencies, discounts.
Shipping : There are carriers, countries, price ranges, weight ranges.
Preferences:
• Appearances: change header logo, metadata and favicon.
• Product settings: change product arrangement.
• Email settings: control email settings (it uses PHPMail() fucntion).
• Image settings: customize your image sizes.
• Database settings: configure database settings.
Tools:
• Employees: customize which users can enter back office.
• Profiles: create types of admin user.
• Permissions: determine which back office user has permission to enter which section.
• Translation: customize language files.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Changing position of a module in prestashop

Prestashop is module based. It uses hooks to load the module. Not every hook can load every module.

To change the position of a module, go to the admin. Then module>positions. You can change position of the modules by clicking the edit button next to every module or you can click the transplant button. In the transplantation form, from the first list, we can choose the module that we want to move and from the second list, we will find the location where we will show the module. The third field accepts file names that will not show the module. These file’s path will be set from the base directory.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Tuesday, August 18, 2009

running php by command line

php 4.3.0 have CLI(command line interface) On by default. Today I am going to say about how to run php by command line in windows.

First of all you need to go to the php folder in your xampp by cmd. If you use svn, then you will have an error saying "Unable to load dynamic library 'E:/xampp/php/ext/php_svn.dll'- the specified module could not be found".

To solve this problem, you need to copy to following files from Apache/bin/ to php/ :

libdb43.dll
intl3_svn.dll
libapr.dll
libapriconv.dll
libaprutil.dll

These will solve the above problem.

Now to execute a php file write the command: php address_of_the_file_to_run(for example E:/xampp/htdocs/tab.php)

you can pass arguments in the command line.And one the server side, you can fetch the argument by the $argv variable, the first element is always the filename that is executing.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Monday, August 17, 2009

I have become a ZCE

I passed the Zend php 5 certification exam on 09, Aug, 2009. I am really very happy. I like to share my experience with you all. I can't tell about the questions as I was asked by Zend not to disclose any of the questions. But I can share my experience ofcourse. I have given the mock exam of zend. The real exam is much harder than the mock ones. One need to know the php manual must for zend php 5 certifications. You also need to have some knowledge about the some php technique by web searching. This will help you lot, because you can learn many things by searching the web. One also need to study the comments made on the php manual. There are many helpful information regarding many complex techniques in php. Keep seeing this blog, i will keep posting many helpfull topics in this blog in the future.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Wednesday, August 5, 2009

Database designing with data modeling tool

Database designing is one of the first phase in developing a software.For database designing there are various tools that we can use.The DBDesigner Fork is a very helpful tool for database designing.

You can download DBDesigner Fork from http://sourceforge.net/projects/dbdesigner-fork/.Then click on the DBDesigner.exe under the bin folder.

Let's start on how to design a table first.Click on the table button on the left column.Then click on the worksplace.A table will be created.You can add field names there by double clicking on it.Drag the field name that you want to make as primary key on the primary key box.

There are one-to-one,one-to-many,many-to-many relationship.To create one of the relationship,first click on one of them that you want to apply. Then click on the two tables you want to connect.

You can build sql commands by DBDesigner Fork.Change the design view to sql view by clicking the first button on left menu.On the sql view,click on a table and drag the table below, you will see the drag menu which will help you to build sql commands.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Tuesday, August 4, 2009

ZEND TEST: UPLOADING FILES

Question : When uploading a file using HTTP, which variable can be used to locate the file on PHP's local filesystem?

Answer :

1. None of the above
2. $_FILES['fieldname']['tmp_name']
3. $_FILES['fieldname']
4. $_FILES['fieldname'][0]['filename']
5. $_FILES['fieldname']['filename']




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

switch control structure in php

Question : The following could be better represented as what?



if($a == 10) {

} elseif ($a == 20) {

} elseif ($a == 30) {

}



Answer:

1. A switch statement without break statements
2. A foreach statement
3. A while statement
4. A switch statement
5. Multiple if statements




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

store information in Http cookie

Question : When is it acceptable to store sensitive information in an HTTP cookie?

Answer:

1. Only under extremely controlled situations
2. When the cookie is sent over a secure HTTP request
3. When it is encrypted
4. It is always acceptable
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

pdo exceptions.

Question: When connecting to a database using PDO, what must be done to ensure that database credentials are not compromised if the connection were to fail?

Answer:

1. wrap the PDO DSN in a try/catch block to catch any connection exception
2. Use constants in the PDO DSN
3. Place the login credentials in the php.ini file
4. Disable E_STRICT and E_NOTICE error reporting levels
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

patterns in zend mock test

Question:

Consider the following series of classes and interfaces
_author;
}
public function getTitle() {
return $this->_title;
}
}
class MyClass2 {
private $_instance;
public function __construct(MyClass $a) {
$this->_instance = $a;
}
public function getTitleAndAuthor() {
$retval = array(
'title' => $this->_instance->getTitle(),
'author' => $this->_instance->getAuthor()
);
return $retval;
}
}
class MyClass3 {
public function doSomething(MyInterface $instance) {
$value = $instance->getTitleAndAuthor();
}
}
?>
MyClass2 is an example of the ________ design pattern.

Answer:

Factory method pattern. As this pattern uses an interface and the subclasses implements that pattern independent of each other.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

design patterns in php 5

Adaptor pattern helps a class to use some interfaces which are not usable by that class without the adapter class.

Singleton pattern has a private and static constructor.so that there will only one instance of a class.

Abstract factory pattern has some abstract class that are override by other classes.

Decorator pattern adds additional features to an object dynamically.

Observer pattern maintains a one-to-main dependency.so,when one object changes other object updated accordingly.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

how to read a csv file in php 5

php provides fgetcsv(resource handle[,int length[,string delimiter[,string enclosure[,string escape]]]]) functions. the length is the number of character that will be read in one line, delimiter will be the end character in a line, enclosure will wrap a field, escape string will esacape double quotes.

it will return an array containing datas of the csv file.
following a source code to parse a csv file.

$row = 1;
$filename="keywords.csv";
if(pathinfo($filename,PATHINFO_EXTENSION)=="csv")
{
$handle = fopen($filename, "r");
echo "table cellpadding='3' cellspacing='3'";
while (($data = fgetcsv($handle)) !== FALSE) {
$num = count($data);
$row++;
echo "tr";
for ($c=0; $c < $num; $c++) {
echo "td".$data[$c]."/td";
}
echo "/tr";
}
echo "/table";
fclose($handle);
}
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Monday, August 3, 2009

disable these directives.

Question: Which of the following php.ini directives should be disabled to improve the outward security of your application?

Answer: (chose 4)

1. safe_mode
2. magic_quotes_gpc
3. register_globals
4. display_errors
5. allow_url_fopen
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

function structure in php

Question : What is the output of the following code?




Answer:

1. Error: Unexpected T_VARIABLE
there must be curly braces surrounding the function body.
2. 10
3. Notice regarding pass by reference
4. 50
5. 5
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

singleton design pattern.

Question : In a situation where you want one and only one instance of a particular object, the ________ design pattern should be used.

Answer : Singleton design pattern.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

variables in php

variables in php must start with _ or any alphabet but can contain number in it. but we can use curly braces to hold a variable that starts with a numeric characters. lets see a zend mock question for php 5 certification preparation.

Question : Which of the following are valid PHP variables?

Answer:

1. @$foo
2. &$variable
3. ${0x0}
4. $variable
5. $0x0
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

passing object in functions in php 5

Question : In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use _______ in the function declaration.

Answer:

1. instanceof, is_a
2. instanceof, type-hinting
3. type, instanceof
4. ===, type-hinting
type-hinting ensures that we are passing a particular type of parameter to a function.
5. ===, is_a
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

fetching next result in pdo

Question : The ________ method in the PDOStatement class is used to return the next result set in a multi-query statement.

Answer: fetch -- this function fetches the next row of the result set.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

concating 2 strings .

implode function and . operator are used to represent an array into string and concate 2 strings. lets see a zend mock question in this regards.

Question :

Given the two values below, which of the following possiblities will print 10 foos20 bars?



Answer: (choose 2)

1. None of the above
2. implode("", array($var1,$var2));
3. $var1 . $var2
4. $var1 + $var2
this will produce 30.
5. All of the above
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

copying a object

Question: What is wrong with the following code?

setValue(10);
$a_copy->setValue(20);

?>


Answer:

1. You must use return &$newObj instead
2. There is nothing wrong with this code
3. duplicate() must accept its parameter by reference
4. You must use the clone operator to make a copy of an object
5. duplicate() must return a reference
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

representing a object as string in php 5

The __toString() magic method is called automatically when an object is represent as a string.

Question: The _______ method will be called automatically when an object is represented as a string.

Answer :

1. getString()
2. __get()
3. __value()
4. __toString()
5. __getString()
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

class constructor in php 5

In php 5, the __construct is the constructor of a class and __destruct is the destructor of the class.previously, in php 4 we are using the class name as a function as constructor of a class.let's see zend mock questions regarding this.


Question: When migrating the following code from PHP 4 to PHP 5, what should be changed?

_doSomething($param);
}

// Private method to MyClass
function _doSomething($param) {
/* Do something with $param */
}
}

class AnotherClass extends MyClass {

var $param = "foo";

function AnotherClass() {
parent::MyClass($this->param);
}
}

?>


Answer:

1. Access modifiers should be added to methods
If no access modifier is present, it treats the variable or method like public.
2. The Constructors for the objects should both be renamed to __construct
3. The use of the parent keyword has changed to 'super'
4. Constructors must have the same parameter lists
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

stream wrappers in php

By creating wrappers we can create user defined protocol for streams.

Question : _______ can be used to add additional functionality to a stream, such as implementation of a specific protocol on top of a normal PHP stream implementation.

Answer:

1. Buffered
2. Buckets
3. Wrappers
4. Filters
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

ZEND MOCK TEST :intersect function list in php 5

there are various kind of intersection functions in php. they are the followings----

array_intersect(array arr1,array arr2,...): it will return the values of arr1 that are in other arrays.
array_intersect_assoc: it will return the values of arr1 with index checking with other arrays.
array_intersect_key: computes comparisons using keys.
array_intersect_uassoc: computes comparisons using association but checking keys by a user function.
array_uintersect_assoc: computes comparisons using association but checking values by a user function.
array_intersect_ukey: computes comparisons using keys.
array_uintersect: computes comparisons using values by a user function.
array_uintersect_uassoc: computes comparisons using association but checking keys and values by a user function.

Question: The following code snippet displays what for the resultant array?

0, 3 => 2, 4 => 6);
$b = array(3 => 1, 4 => 3, 6 => 4);

print_r(array_intersect($a, $b));
?>

Answer:

1. 1 => 0
2. 1 => 3, 3 => 1, 4 => 3
3. 3 => 1, 3=> 2, 4 => 3, 4=> 6
4. 1 => 0, 3 => 2, 4 => 6
5. An empty Array
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

request superglobal array in php

The $_REQUEST superglobal array contains gpc variables.

Question: The $_REQUEST super global contains what?

Answer:

Data received from the session
Data received from Cookies
Data received from the server environment
Data received from HTTP POST
Data received from HTTP GET
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

sqlite performance improvement

lets see a zend mock question related to sqlite.

Question: Which of the following SQL statements will improve SQLite write performance?

Answer:

1. PRAGMA locking_mode = "Row";
2. PRAGMA count_changes = Off;
3. PRAGMA default_synchronous = Off;
4. PRAGMA default_synchronous = On;
5. PRAGMA locking_mode = "Table";
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

autoloading in php 5

it was a hassle to add every class at the beginning of a file to use it in it.php5 comes with a solution for this problem. we can use __autoload function for this purpose. it will automatically load the class.

Question: Rather than manually providing the class declaration for every class as you had to in PHP 4, in PHP 5 you can define the _________ function, which will give your script the opportunity to automatically find and load a particular class upon instanciation

Answer: __autoload
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

ZEND PREP :returning function in php

we can get a result from a function only by using return or echo keywords. so, if there is no return or echo,then the function will not give any output. let's zend mock certification question for php 5.

Question:

What is the output of the following?



Answer:

1. 0
2. 36
3. 6
4. 30
5. 5
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

builder pattern

Builder design pattern is a creational design pattern. this means it creates an object step by step. In simple, the builder pattern uses an abstract class which has some common functions in it. this class is called as builder.there is a class that implements the builder class which is called concretebuilder. there is another class called director class which creates object of conretebuilder class step by step.so the pattern structure will be like

abstruct class abstruct1
{

}

class concretebuilder extends abstruct1
{

}

class director extends concretebuilder
{

}
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

passing by reference in php

Passing a variable by reference will change the value of the variable.

Question : What is the output of the following?



Answer:

1. 50
2. 5
3. 95
4. 10
5. 100
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

ZEND MOCK :adding element at the beginning of an array

we can add elements at the beginning and at the end of an array in php.let's see a zend preparation questions for php 5 mock exam.


Question: Which function would you use to add an element to the beginning of an array?

Answer:

1. array_shift()
This function is used to remove element from the beginning of the array.
2. array_push();
This function is used to add element at the end of the array.
3. $array[0] = "value";
4. array_unshift()
This function is used to add element at the beginning of the array.
5. array_pop();
This function is used to remove element from the end of the array.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

reassigning this in php 5

In php 5 you can't assign a variable to $this. It will produce a fatal error.

Question: What is wrong with the following code valid in PHP 4 but invalid in PHP 5?

reassign($b);

?>

Answer:

1. Reassigning $this in PHP 5 throws a fatal error
2. It is missing access restrictions (public,private,protected) required in PHP 5
3. Classes need to implement the OverLoad interface for this behavior in PHP 5
4. $b is now an object handle and the reassign() method needs to be declared pass-by-reference
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

ZEND MOCK TEST PREPARATION: comparison in php

php provides many ways to compare 2 variables. == operator doesn't check the type of the operands. it just compare the 2 operands with matching the type. === operator checks for the types of the operands also. If a string contains any numbers before having any characters in it like "1time", then === operator matches it with integer value "1". Any string without initial number are treated as 0 when converted to integer. let's see a zend mock question for php 5 certification.


Question: Which of the following comparisons will evaluate to true?

Answer:

1. 't' == t
2. 1 === "1time"
3. "top" == 0
4. "top" === 0
5. 1 == "1time"
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Saturday, August 1, 2009

viewing sent headers

Question: Consider the following function:

function redirect($url) {
// Check to make sure we haven't already sent
// the header:

if(???????) {
header("Location: $url");
}
}

?>
What conditional should replace the ????? above?

Answer:

1. !in_array("Location: $url", headers_list())
2. !header_exists("Location: $url")
3. !header_location($url)
4. $_SERVER['HTTP_LOCATION'] != $url
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Friday, July 31, 2009

zend php 5 certification : filtering input

We should not trust any input from any source.The source could be a user, url or database value, any thing. Every input data must be filtered. unfiltered data makes your system vulnerable to attacks. php offers many input filtering functions. Let's a mock zend php 5 certification question regarding this.


Question : What is the best way to ensure the distinction between filtered / trusted and unfiltered / untrusted data?

Answer:

1. None of the above
2. Never trust any data from the user
3. Enable built-in security features such as magic_quotes_gpc and safe_mode
4. Always filter all incoming data
5. Use PHP 5's tainted mode
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Thursday, July 30, 2009

short introduction to jmeter

Now let’s see how the process to install jmeter. You can download it from http://jakarta.apache.org/site/downloads/index.html. You need Java 4 or newer to run jmeter. After unzipping click the jmeter.bat under bin folder.

1. First of all, by right clicking on the workbench we can add a HTTP proxy server.
2. Set the proxy server of the browser to localhost and the port to 8080.
3. Start the HTTP proxy server and reload the site that u want to test on your browser. You will see the changes in the jmeter. By clicking them, you will see the header sent for them. On clicking the header, you will see the header information. By click the page, you can edit the http data for the request. After loading the page, you need to stop the server.
4. Now we will make a test plan. We will make a thread group first by right clicking on it. In the thread group , you will see thread properties. Number of thread means the number of users that will try to see your site. Ramp-up period means the time interval between two successive users. If you set 0,this means the users access at the same time. Loop count is how many times the test will run.
5. Now we will add those section that we want to test. Right click on the section, that show site address without hostname. Select copy and paste it in thread group.
6. Now we will add some listener to see the test result. There are lots of listeners . I use graph result, monitor result, simple data writer, spine visualizer, summary report, view results in table, view results tree. I will explain the different uses of these listener later on.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

unit test in software development.

Regression testing is performed after the software quality assurance team has done their work perfectly. And of course, after the developers have done the unit testing which means testing a class independently in object oriented environment or a procedure or method in procedural environment. Unit test is used to test whether an independent piece of code is working properly and if an error occurs, a developer can easily identify the problem. This kind of testing is very helpful. It follows the bottom-up approach of testing that means first checking the smallest chunk of code independently and then check with other parts integrated. Unit test case can be made with the available UML tool these can be found as an extension to an IDE. With the unit-test design method, the tests will never pass if the developer does not implement the solution according to the design. To obtain the fruit of unit testing, the software process must follow the steps of software development.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

regression testing with jmeter.

Jmeter is a regression testing tool. Software regression means a software bug that makes a feature stop which was working correctly earlier. Sometimes a feature gets too much slow or uses too much memory. Regressions are generally caused due to encompassed bugs. Encompassed bugs are not a bug but a side effect of some critical issues. So, to handle these bugs we need to have some test plan. Software regression mainly occurs for one of the following three reasons. They are-
1. Local – a change introduces a new bug that was not before.
2. Remote – a change in one part of the software that introduces a new bug in other parts.
3. Unmasked – a change unmasks an already existing bug that was not there before.
So, regression tests composed of tests which will check the effectiveness of the site. These things are tested using Jmeter. Jmeter tests a site by running a site concurrently for several times.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Wednesday, July 29, 2009

Zend PHP 5 Certification Mock Exam: pdo dsn

Question:

Which of the following is not a valid PDO DSN?

Answer:

1. All of the above are valid
2. mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
3. oci:dbname=//localhost:1521/mydb
4. mysql:host=localhost;port=3307;dbname=testdb
5. sqlite2:/opt/databases/mydb.sq2
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

session related question in zend mock test for zend php 5 certification

Question: When implementing a permissions system for your Web site, what should always be done with regards to the session?

Answer:

1. None of the above
2. You should not implement permission systems using sessions
3. Sessions should be cleared of all data and re-populated
4. The session key should be regenerated

5. The session should be destroyed
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

array walk function

array_walk_recursive(array & input,callback func[, mixed userdata]) to walk with a callback function recursive.

Question:

Which key will not be displayed from the following code block?


$array = array('a' => 'John',
'b' => 'Coggeshall',
'c' => array('d' => 'John',
'e' => 'Smith'));

function display($item, $key) {
print "$key => $item\n";
}

array_walk_recursive($array, "display");

?>

Answer:

1. d
2. c
any key that contains an array will not be shown.
3. b
4. a
5. They all will be displayed
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

transaction in php

Question:

Which of the following cases are cases when you should use transactions?

Answer:

1. Updating a single row in a table
2. Inserting a new row into a single table
3. Performing a stored procedure
4. Selecting rows from multiple different tables
transaction is not use in select statement.
5. Updating a single row in multiple different tables
transaction is used in multiple tables for updating process.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

combine 2 arrays

array_combine(array keys,array values): will return an array where 1st array will be the key and the 2nd array will be the value. this is new in php5.

array_reverse(array input[,bool preserve_keys]) will reverse the input array.

Question:

What should go in the missing line ????? below to produce the output shown?

$array_one = array(1,2,3,4,5);
$array_two = array('A', 'B', 'C', 'D', 'E');

???????

print_r($array_three);
?>
Result:

Array
(
[5] => A
[4] => B
[3] => C
[2] => D
[1] => E
)


Answer:

1. $array_three = array_merge(array_reverse($array_one), $array_two);
2. $array_three = array_combine($array_one, $array_two);
3. $array_three = array_combine(array_reverse($array_one), $array_two);
4. $array_three = array_merge($array_one, $array_two);
5. $array_three = array_reverse($array_one) + $array_two;
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

extracting substring

lets see a zend mock question regarding extracting substring.

Question:

Given the string:
$var = "john@php.net";
Which of the following will extract the TLD (top level domain) of ".net" from the string?


Answer:

1. strstr($var, strpos($var, "."));
the second parameter of strstr is the needle.

2. substr($var, strpos($var, "@"));
3. substr($var, strstr($var, "."));
the second parameter of substr is the offset.
4. substr($var, strpos($var, ".") + 1);
it will extract net.
5. substr($var, strpos($var, "."));
it will extract .net
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

pass by reference in php 5

let's see a zend mock test question for php 5 certification.

Question:

Consider the following script:


This code has changed behavior in PHP 5. Identify the output of this script as it would have been in PHP 4, as well as the new behavior in PHP 5.


Answer:

1. array('a', 'a', 'b')
2. array('a', 'b', 'c')
This will show in php 5.
3. array('c', 'b', 'a')
4. array('c', 'c', 'c')
I think this will be the result for php 4.
5. array('b', 'b', 'b')
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

destroying session varriables

Question:

To destroy one variable within a PHP session you should use which method in PHP 5?

Answer:

1. Unset the variable in $HTTP_SESSION_VARS
2. Use the session_destroy() function
this function destroy all session varriable in the current session. but not unregister them.
3. Use the session_unset() function
this will unregister all the session varriables.
4. unset the variable in $_SESSION using unset()
this will unregister the session varriable.
5. Any of the above are acceptable in PHP 5
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

placing include files

users can easily access files that are in the document root. so, it is safe to place configuration and log files outside of the document roots. and you can use those file by using include/require or better to use include_once/require_once.Lets see zend mock questions regarding this.

Question:

Where should indirectly executed PHP scripts (i.e. include files) be stored in the file system?

Answer:

1. Outside of the Document Root
2. In the document root
3. Anywhere you want
4. In the database
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

xpath query in php

Lets see the zend mock php 5 certification question on xpath.

Question:

Consider the following simple PHP script:


$dom = new DomDocument();
$dom->load('test.xml');
$xpath = new DomXPath($dom);
$nodes = $xpath->query(???????, $dom->documentElement);
echo $nodes->item(0)->getAttributeNode('bgcolor')->value
. "\n";

What XPath query should go in the ?????? above to display the "bgcolor" attribute of the first "body" node in the XML document?


Answer:

1. "*[local-name()='body']"
2. "/body[0]/text"
3. "/body/body[0]"
4. "name='body'"
I am not sure about this. my answer is this.
5. "*[lname()='body']"
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

static keyword in php 5

Static varriables and constants are accessed by the scope resolution operator. But it will not show any errors. If you set the error level to E_STRICT, then it will show an error.


Question:

Consider the following PHP 4 code snippet:

value = $value;
}

function doSomething($myClass) {
$myClass->setValue(10);
}
}

$myClass = new MyClass();
MyClass::doSomething($myClass);
?>
In PHP 5, will this code change behavior? Why or why not?

Answer:

1. No, Not unless E_STRICT is enabled
2. Yes, you have to declare doSomething() static now
3. Yes, objects are now reference based
4. No, it will function exactly the same
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

varriable in

php varriables remain as the varriable within a single quote, but in double quotes they have their values in them. We can use curly braces in double quotes for using with varriable.

Question:

Which of the following are not valid ways to embed a variable into a string?

Answer:(choose 2)

1. $a = "Value: $value->getValue()";
I am not sure about this.
2. $a = "Value: {$value}";
3. $a = 'Value: $value';
it will output Value: $value.
4. $a = "Value: $value";
5. $a = "Value: {$value['val']}";
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

output xml string

The asXml([string filename]) returns a well-formed xml string to the output. If a filename is specified then it is written to the file.


Question:

Given the following PHP script:



$xmldata = XML
?xml version="1.0" encoding="ISO-8859-1" ?
!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
head
title XML Example/title
/head
body
p
b Hello, World! /b
/p
/body
/html
XML;

$sxe = simplexml_load_string($xmldata);

$p = $sxe->body->p;

$string = ????????

print $string;



What should go in place of ????? above to print the string Hello, World! (with no leading/trailing whitespace or markup)?


Answer:

1. trim(($p[1]));
2. trim(strip_tags(($p->asText())));
There is no such function named asText()
3. trim(strip_tags(($p->asXML())));
4. trim(($p->asXML()));
5. strip_tags(($p->asXML()));
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

xml dtd

Question:

What XML technology is used when you mix two different document types in a single XML document?

Answer:

1. Validators
2. DTD
DTD describes the document type definition of a xml document.
3. Transformations
4. Namespaces
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

hashing in php

First of all, i don't know what is fingerprint. but i think the question was asking about hashing a string. and there are lots of ways in php that will help us hashing a string. but hash(string algo,string string[,bool raw_outputs]) is the most appropriate for this as this function can use different algorithms for hashing.this functin is new in php 5.

Question:
A fingerprint of a string can be determined using which of the following?

Answer:

1. md5()
2. hash()
3. fingerprint()
no such function.
4. None of the above
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

setting timeout in streams

Question:
The ____________ function is used to modify the amount of time PHP will wait for a stream before timing out during reading or writing.

Answer:

stream_set_timeout(resource stream,int sec[,int microsec=0]) sets the timeout period.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

function name

In php, a function name can be alphanumeric and underscore. but the first character can't be a number. let's see the zend mock question for this.

Question:

What is the output of the following?

function 1dotEach($n)
{
if ($n > 0)
{
1dotEach(--$n);
echo ".";
}else
{
return $n;
}
}
1dotEach(4);
?>


Answer:

1. ....0
2. Parse Error: Syntax Error
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

pdo attribute

we can set different attributes on pdo. let's see zend mock question for this .

Question:

When writing portable database code using PDO, what is the PDO::ATTR_CASE attribute useful for?

Answer:

1. None of the above
2. Ensuring that all columns are of a particular case when fetched
3. Adjusting the case of a query before it is processed for compatibility reasons
4. Controls the switch logic of how queries are processed
5. Allows you to adjust the memory cache (or "case") for increased performance
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

xml question

The following is question regarding xml. I am not sure of the answers.

Question:

Consider the following example XML document:

?xml version="1.0" encoding="ISO-8859-1" ?
!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
head
title XML Example /title
/head
body
p
Moved to a href="http://example.org/" http://www.example.org//a.
br
/p
/body
/html
What is wrong with this document, and how can it be corrected?


Answer: (choose 2)

1. The document is completely valid
2. All special XML characters must be represented as entities within the content of a node
3. All tags must be closed
4. You cannot specify a namespace for the html attribute
This is not right. one can specify a namespace for the html attribute.
5. The DOCTYPE declaration is malformed
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

reverse a string in php

Let's see the zend mock test question.

Question:

Which functions would be needed to translate the following string:
I love PHP 5
to the following?
5 PHP EVOL I

Answer:(choose 2)

1. mirror()
2. strtoupper()
it will convert the string to uppercase.
3. toupper()
4. str_reverse()
5. strrev()
it will reverse the string.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

octal and hexadecimal values in php

For calculating octal numbers the formula is
$a=010

$a=1x8^1+0x8^0=8

For hexadecimal values

$b=0xA

$b=10

Here A=10,...,F=15.

Question :
What is the output of the following?


$a = 010;
$b = 0xA;
$c = 2;

print $a + $b + $c;

?>

Answer:

1. 20
2. 22
3. 18
4. $a is an invalid value
5. 2
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

handling cross-site request forgery

csrf exploits the trust of application on user. csrf attacks are best way to handle by sending a form with post method. There can be a way to prevent csrf with adding a secret token in form hidden field.


Question : What is the best measure one can take to prevent a cross-site request forgery?

Answer:

1. Disallow requests from outside hosts
2. Add a secret token to all form submissions
3. Turn off allow_url_fopen in php.ini
4. Filter all output
5. Filter all input
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

array element in php

Let's see zend php 5 mock test question regarding arrays below.

Question:
What is the output of the following code?


$string = "14302";

$string[$string[2]] = "4";

print $string;

?>

Answer:

1. 14304
2. 14342
3. 44302
4. 14402
5. Array
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

spliting a string in php

There are several functions in php to split a string.

1. The simplest and most efficient is to use explode(string delimiter,string str[,int limit]) function.

2. we can use str_split(string str[,int length]). this function split a string with each being upto specified length.This is new in php 5.

3.split(string pattern,string string[,int limit]) functions splits a string with pattern and the array size will be upto limit size with the last one containing the rest of the string.

4.preg_split(string pattern,string str[,int limit[,int flags]]) returns an array containing the matched substrings upto limit number of arrays.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

split a string.

let's see the zend mock exam question related to splitting a string in php.

Question: Which of the following is the best way to split a string on the "-=-" pattern?

Answer:

1. They all are equally proper methods
2. str_split($string, strpos($string, "-=-"))
3. preg_split("-=-", $string);
4. explode("-=-" $string);
it doesn't have a ','.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

php streams features

streams in php has the following properties.

1. streams uses less memory and can handle large data.
2. streams are accessed like files.
3. streams are sometimes seekable.
4. streams may be unidirectional.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

stream class

let's see a question of zend certification mock test regarding stream's feature.

Question: Which of the following are not true about streams?

Answer:

1. They are always seekable
2. When used properly they significantly reduce memory consumption
3. They can be applied to any data source
4. They are always bi-directional
5. They can be filtered
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

retrive the function arguments in php

The func_get_args() function returns an array of argument that a function has in it's parameter list. There are also func_num_args() and func_get_arg() functions which can be used to get function parameter information. let's see zend mock certification test question below.

Question:
What would you replace ??????? with, below, to make the string Hello, World! be displayed?



Answer:

1. There is no way to do this
2. $string = $argv[1];
3. $string = $_ARGV[0];
This will return the script name.
4. list($string) = func_get_args();
5. $string = get_function_args()
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

strip_tags function for php

php provide a function named strip_tags(string str[,array allowable_tags]). we can strip html tags using this function. But this is function is not safe totally as the allowable_tags parameter will can those tags that will not be stripped off. So, we can totally rely on strip_tags for input filtering and output escaping. Let's the zend mock question for php 5 certification.

Question: When using a function such as strip_tags, are markup-based attacks still possible?

Answer:

1. No, HTML does not pose any security risks
2. Yes, even a

HTML tag is a security risk
3. Yes, attributes of allowed tags are ignored
strip_tags does not strip allowable tags.
4. No, strip_tags will prevent any markup-based attack
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide





List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Tuesday, July 28, 2009

file access in php security.

In php we have doc_root,user_dir and open_basedir option to control file access using php.If we Specify the doc_root,then every request for opening a file will be checked against the doc_root.If it is not under the doc_root, the request is discarded.Another one is user_dir. user_dir is used with respect to doc_root.If a user_dir is specified then a request is checked whether the file is in the doc_root and then is it in the user_dir. open_basedir controls which files will be opened using php. we must use a trailing slash after the file name to be more secure.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

displaying errors in a site.

Error message shows mainly database related error messages. Lets see the mock zend php certification question.

Question: Why is it important from a security perspective to never display PHP error messages directly to the end user, yet always log them?

Answer:(choose 2)

1. Error messages will contain sensitive session information
session information are not shown in a error message.
2. Error messages can contain cross site scripting attacks
xss attack is not possible with such error message.
3. Security risks involved in logging are handled by PHP
4. Error messages give the perception of insecurity to the user
5. Error messages can contain data useful to a potential attacker
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

output buffering

There will be no output before any headers are sent.But we can use output buffering to sent headers. The output code will be between ob_start and ob_clean functions. Let's see the mock zend certification test question.

Question: One can ensure that headers can always be sent from a PHP script by doing what?

Answer:

1. Enable header buffering in PHP 5
2. Set the header.force INI directive to true
3. Enable output buffering in PHP 5
4. There is no way to ensure that headers can always be set, they must always be checked
5. None of the above
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

static methods in php

Static methods can be accessed by self keyword within the class and we can't use this keyword. Let's see the mock zend certification test question.

Question: What is the primary difference between a method declared as static and a normal method?

Answer:

1.Static methods can only be called using the :: syntax and never from an instance
2.Static methods do not provide a reference to $this
3.Static methods cannot be called from within class instances
4.Static methods don't have access to the self keyword
5.There is no functional difference between a static and non-static method
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

array index

Array index can be string or integer. The following a problem regarding array index. Let's see the mock zend certification test question.

Question:
What is the output of this code snippet?


$a = array(0.001 => 'b', .1 => 'c');

print_r($a);

?>

Answer:
1. An empty array
2. 0.001 => 'b', .1 => c
3. 0 => 'c'
Because the fractional part will be converted to the nearest integer.
4. '0.001' => 'b', '0.1' => c'
5. A Syntax Error
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

object comparison

Object comparison has got some change in php 5. Object comparison using === operator will mean that 2 objects are of same instance of a class, where as using == operator means the 2 objects have same attribute and value and of the same class. This is will be helpful for zend php certification. Let's see a mock test question. The bold one is my answer , you can give yours in comment.

Question: what compatibility problem will this conditional has in php5 .

if($obj1==obj2){}

Answer:

1.This code is undefined in PHP 4
2.None of the above
3.$obj1 and $obj2 must have the same property values in PHP 5 .

This is true for == operator.
4.$obj1 and $obj2 must be the same instance in PHP 5 .

this is right answer.
5.There are no compatibility issues
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

sqlite features.

Sqlite is a popular lightweight faster database. There will be some question regarding sqlite in zend certification exam. There are some features of sqlite below-
  • It is transactional means it has the ACID propertis.
  • It has zero-configuration setup means it needs no configurations for setup.
  • It can store upto terabyte sized databases and gigabyte sized strings.
  • Sqlite is faster compare to other databases.
  • It has simple, easy to use api.
  • complete database is stored in a disk file.
  • use less memory and bandwidth.
  • it does not support foreign keys.
  • types are assigned to values.
  • concurrent read is possible, but concurrent write is not possible.
  • this is not a client-server database.
  • the data are read as numeric and textual.
Drawbacks:
  • it does not support domain integrity.
Some uses of sqlite is stated below--

  • we can use it for writing xml data to files. It will then support transactional properties, cross platform and avoid the hassles of parsing.
  • it is used in mobile phone, PDA and other electronic gadgets.
  • it is popular with small and medium-sized websites.
  • it can be used for testing sites.





List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

make fun with streams

Streams help us to read and write file systems. PHP provide us some functions. I am giving some short description for some stream functions. These are important for zend php certification exam.

1.stream_wrapper_register(string protocol,string classname[,int flags]): This function is used to register user defined wrappers.

the protocol is the wrapper name, classname is the classname that will define the wrapper and the flag says whether it is defined by the url.

2.stream_wrapper_restore(string protocol): This function restores a previously unregistered built-in wrapper. This is new in php 5.

3.stream_wrapper_unregister(string protocol): This function unregister a wrapper. This is new in php 5.

4.stream_context_create([array options[,array params]]): creates a context with options and params.

5.stream_context_set_option(resource context,array options): set options.

6.steam_context_set_params(resource context,array options): set params.

7.stream_context_set_default(array options): set options for default context.This is new in php 5.

8.stream_context_get_default([array options]): get the default context.This is new in php 5.

9.stream_copy_to_stream(resource source,resource dest[,int maxlength=-1[,int offset=0]]):copies stream .This is new in php 5.

10.stream_filter_register(string filtername,string classname): register a user defined filter. the class has onCreate(),onClose,filter functions.

11.stream_filter_prepend/append(resource stream,string filter[,int read_write[,mixed params]]): prepend a filter. The read_write parameter could be STREAM_FILTER_READ,STREAM_FILTER_WRITE,STREAM_FILTER_BOTH.The params will be prepended at the beginning of the stream.

12.stream_get_filters(): get list of filters. This is new in php 5.

13.stream_get_wrappers(): get list of wrappers. This is new in php 5.

14.stream_get_transports(): get list of transports. This is new in php 5.

15.stream_get_meta_data(resource stream): returns information of the current stream. It contains whether the stream is blocked, time out , how much is left for reading,seekable, stream mode, wrapper data type,filter, end of file. This function does not work on sockets.

16.stream_get_line(resource handle,int length[,string end]): gets line from the given handle upto a string end without the end string. This is new in php 5.

17.stream_filter_remove(resource stream_filter):removes the filter added before. This is new in php 5.

18.stream_get_contents(resource handle[,int maxlength[,int offset]]): gets the remaining contents of the stream. This function works on a open file stream.This is new in php 5.

19.stream_is_local(resource handle): checks whether it is local or a url.This is new in php 5.

20.stream_notification_callback(): a callback function for notification context parameter.This is new in php 5.

21.stream_select(array &read,array &write,array & except,int tv_sec[,int tv_usec=0]): This function accepts an arrays of streams and waits for status. It returns the streams that are available within the time out seconds.

22.stream_set_blocking(resource stream,int mode): sets blocking/non-blocking mode.

23.stream_set_timeout(resource stream,int sec[,int usec=0]):set timeout period,expressed in the sum of sec and usec.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Monday, July 27, 2009

pdo setAttribute function

The pdo function setAttribute(int attribute,mixed value) sets different attributes on database connection. The attributes are the followings-

1. ATTR_CASE : sets the case of the column names.
2. ATTR_ERRMODE: error reporting.
3. attr_stringify_fetches: converts numeric values to strings when fetching.
4.attr_statement_class: sets the user supplied statement class using pdostatement class.
5.attr_autocommit: whether to autocommit.
6.MYSQL_ATTR_USE_BUFFERED_QUERY: use buffered query.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Simple API for XML

SAX means simple api for xml. It is built with java first. It is event-based xml parsing method.Dom uses tree-based xml parsing method. Dom parses the whole tree first. So, it can move to any position to change the data. Below are some properties of SAX.

1. It is event-based.
2. SAX can't move backward. It is unidirectional.
3. SAX can process data before loading the complete data.
4. It consumes less memory than DOM.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Testing with jmeter

We can test a site's performance using jmeter. Though we can get the same functionality by firebug, but firebug shows the statistics for only one request, where jmeter shows for several users.

To use jmeter first you need to download the latest version from the web. Your need java 4 or latter to be installed in your machine to install jmeter. You need jre also. You have to set the path of jre as the system variable. After unziping the folder, click the jmeter.bat under bin folder. It will open the jmeter. Under the workbench, create proxy http server by right clicking it.You have to change the proxy settings of the browser by going to tools, then options, choose manual proxy settings.Enter localhost and port is 8080. Then restart the website that you want to test. you will see some changes in the jmeter window. Now under test plan , create thread group by right clicking. Then from the listed enteries of the testing site, only copy the section that is for the page, don't take any image,js, css files, that will make huge load for ur testing. Now add some listeners. you can add graph,summary result etc to see the results. And under the thread group, change the number of users to 100 or the number u want to test. This shows the number of users that are concurrently accessing the site.

You can view the result in the listeners. If you want to make another test, just clear all the results.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Saturday, July 11, 2009

With DOM (document object model), we can add or remove a node in xml with DOM. DOM comes up with many powerful features. Let see the question now for preparation of ZEND certification test. The bold options are the answers. You can give your opinion about the answers.
Question: What should go in the missing line ????? below to produce the output shown?

$array_one = array(1,2,3,4,5);
$array_two = array('A', 'B', 'C', 'D', 'E');

???????

print_r($array_three);

Result:

Array
(
[5] => A
[4] => B
[3] => C
[2] => D
[1] => E
)

a. $array_three = array_merge(array_reverse($array_one), $array_two);
b. $array_three = array_combine($array_one, $array_two);
c. $array_three = array_combine(array_reverse($array_one), $array_two);
This is the right answer.The array_combine function takes 2 arguments. One is keys and other is values. If the length of the arrays are not match or the array is empty , then E_WARNING is thrown.

d. $array_three = array_merge(array_reverse($array_one), $array_two);
e. $array_three = array_combine($array_one, $array_two);




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Event-based XML parsing:

With DOM (document object model), we can add or remove a node in xml with DOM. DOM comes up with many powerful features. Let see the question now for preparation of ZEND certification test. The bold options are the answers. You can give your opinion about the answers.
Question: Event-based XML parsing is an example of which parsing model?
a.SAX
SAX is event-based xml parsing method.
b.DOM
DOM is tree-based xml parsing method.
c.XML Object Mapping
d.XPath
e.XQuery




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Friday, July 10, 2009

Showing error info in PDO:

There are 3 values in the array that is returned by the errorinfo function in PDO.Let see the question now for preparation of ZEND certification test. The bold options are the answers. You can give your opinion about the answers.
Question: Consider the following PHP code segment, which attempts to execute a PDO query:

try {
$dbh->exec($sql);
} catch (PDOException $e) {
// display warning message
$info = $e->errorInfo;
}

In the event of a PDOException, $info is set with the contents of the $errorInfo property of the exception. Which of the following are accurate descriptions of the contents?

a.$info[1] is the database-specific error code
This is right.
b.$info[2] is the database-specific error message
This is right.
c.$info[1] is the unified error code
d.$info[0] is the unified error code
This is right.
e.$info[0] Is the Database-specific error message




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Wednesday, July 8, 2009

Closing Tags in php code blog:

Php interpreter can recognize a php code block by it’s tags. When it founds a starting tags, then it knows that the flowings are the php code to process. You can omit the closing tags. This will not make any difference, rather it will help to avoid an error. If there is any white space after the closing tags, then php will throw an error. There are 4 php tags. Let see the question now. The bold options are the answers. You can give your opinion about the answers.
Question: Which of the following tags are an acceptable way to begin a PHP Code block?[choose 4]
a. "e;script language=”php”"e; "e;/script"e;
This is the javascript style php tag.
b. "e;!
This tag is invalid.
c. "e;%
This is ASP style tag.
d. "e;?php
This the default php tag.
e. "e;?
This is the short tag for php.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Tuesday, July 7, 2009

Arguments of a function

I will show you all a question regarding argument passing to a function in php. In php 5.3.0 we can assign NULL by reference to any argument. Now let’s see the question of ZEND mock test. The bold options are the answers. You can give your opinion about the answers.
Question: Which of the following is incorrect?[choose 4]
a. function c(MyClass $a = new MyClass())
You can't create an object of a class in this way.
b. function d($a = null)
php 5.3.0 gives option to set argument as null.
c. function e(&$a = 30)
You can’t assign default value to a parameter by reference.
d. function a(&$a = array(10,20,30))
Arrays can not be assigned to an argument.
e. function b($a = (10 + 2))
you can not assign an expression to an argument In a function.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Sunday, June 21, 2009

Web Security in php programming

Security section is very import for web development. Every user get scared if his data is looted from the websites. There are many issues which are related to web security. That’s why we are so concerned with web security.
To protect our web application, the first thing is never trust any input. We must escape every inputs properly. Php comes with many escape functions .For input escaping , htmlentities() function converts all applicable characters to HTML entities. It has 4 parameters. The first arguments takes the string to escape. The second argument is the quote style. There are 3 types of styles:
1. ENT_COMPAT: this will convert double quotes and leaves the single quotes.
2. ENT_QUOTES: this will convert both single and double quotes.
3. ENT_NOQUOUTES: this will leave both single and double quotes.
The third parameter is the charset. The default is ISO-8859-1 and the fourth parameter is double_encodes. If it is set to off , then php will not encode existing html entities, the default is On.
There is a similar function called htmlspecialchars() with the exception is that htmlentities convert all characters and htmlspecialchars encodes only special characters.
The translations performed are:
• '&' (ampersand) becomes '&'
• '"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
• ''' (single quote) becomes ''' only when ENT_QUOTES is set.
• '<' (less than) becomes '<'
• '>' (greater than) becomes '>'
This function has the same 4 parameters of htmlentities. These 2 function uses the html translation table. We can find with the function get_html_translation_table.
$trans = get_html_translation_table(HTML_ENTITIES);
$str = "Hallo & & Krämer";
$encoded = strtr($str, $trans);

echo $encoded;
?>
We can decode the encoded string with respective decode functions : html_entity_decode and htmlspecialchars_decode .

The functions urlencode and rawurlencode is used for encoding data on the url. This helps to hide any important data from possible attackers. The difference between these 2 is that the first function converts spaces into ‘+’ sign. Urldecode and rawurldecode decodes the encoded data. The encoded data in $_GET and $_REQUEST method automatically decodes data.

Filtering data:
So, We must filter any input data before use. There are 2 approaches .
1. Blacklist approach: In this approach, we assume every thing is secure except the some given listed data. If any input matches the given data, we will treat is as tainted.
2. Whitelist approach: This approach assumes that all are tainted except some given data. If a data matches this given data, then we can say this data is safe to proceed.
We can use ctype_* and is_* functions for filtering inputs. These functions check whether the given data is our required data type.
if (ctype_alpha($_POST[’username’]))
{
$clean[’username’] = $_POST[’username’];
}
if (ctype_alnum($_POST[’password’]))
{
$clean[’password’] = $_POST[’password’];
}
$colours = array(’Red’, ’Blue’, ’Yellow’, ’Green’);
if (in_array($_POST[’colour’], $colours))
{
$clean[’colour’] = $_POST[’colour’];
}
Here we are checking the input data whether they are of specified type. Sometimes client-side javascript validation is not necessary for filtering, as there is one security issue called ‘spoofed form’. We will talk about this later. So, we must not rely on client-side javascript. We need to use server side filtering also.

This is not all about web security in php world. We will focus on the rest later on.




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide