I am moving to http://www.tanzilo.com
March 30, 2008
Hello visitors,
I have prepared my personal blog using the WordPress package. So, from now on I will be writing in my personal blogs. I wish to continue writing more articles, codes & tutorials for my visitors.
OK. Here is my personal blog : http://www.tanzilo.com
Everyone is welcome.
Often we need to subtract years, months, days, hours, minutes and even seconds from current time or any other time. Previously I wrote a script and/or tutorial on how to add time. This script is nothing but a little modified version of the previous script to deduct or subtract time. I wrote this script since several people often come to search the time adding script. So, I wrote this script to check if this is helpful for any one.
Okay. Here is the PHP function to subtract or decuct time.
<?php
function subtractTime($hours=0, $minutes=0, $seconds=0, $months=0, $days=0, $years=0)
{
$totalHours = date(“H”) – $hours;
$totalMinutes = date(“i”) – $minutes;
$totalSeconds = date(“s”) – $seconds;
$totalMonths = date(“m”) – $months;
$totalDays = date(“d”) – $days;
$totalYears = date(“Y”) – $years;
$timeStamp = mktime($totalHours, $totalMinutes, $totalSeconds, $totalMonths, $totalDays, $totalYears);
$myTime = date(“Y-m-d H:i:s A”, $timeStamp);
return $myTime;
}
?>
Now we call the function to test the output.
<?php
// Let us first see the current time
echo ‘Current Time: ‘ . date(“Y-m-d H:i:s A”);
echo ‘<BR>’;
// Now let us deduct 5 hours, 2 days and 1 year from now
echo ‘New Time: ‘ . subtractTime(5,0,0,0,2,1);
?>
And here is a sample output:
Current Time: 2008-03-23 21:40:28 PM
New Time: 2007-03-21 16:40:28 PM
Thus, you can subtract or deduct time (such as second, minute, hour, day, month, year) easily with a simple function.
If you are a website developer, it will be a really valuable action if you test whether your page passes the W3C validation standard. But why should you do this? If your pages pass W3C standard, it is often guaranteed that your pages will load quicker in modern web browsers and be easier to maintain. You can validate your pages directly from World Wide Web Consortium’s website. And the link is here: http://validator.w3.org.
We can write a JavaScript that can validate a page on given parameter. Below I have written a very simple JavaScript function to test a page’s web standard. But you can customize it according to your requirements. This kind of JavaScript function can be helpful when we have lots of pages and we need to check them one by one by just clicking a button. Now let us make a HTML page with a JavaScript function and we will give validator.html as its name. The page’s code is as below:
<html>
<head>
<title>W3C Web Standard Test</title>
<script language=”javascript” type=”text/javascript”>
function testMyPage(webpageLocation)
{
var url = ‘http://validator.w3.org/check?uri=’ + webpageLocation;
window.open(url, ”, ‘width=775, height=500, status=yes, resizable=yes, scrollbars=yes, location=yes’);
}
</script>
</head>
<body>
<input name=”Button” type=”button” value=”Test My Page” onclick=”testMyPage(‘www.wordpress.com’);” />
</body>
</html>
A new window opens with your given page location i.e. url as below:

Remember that the above window may not appear if you have a pop-up killer active. I suggest you turn off the pop-up killer program (if any) to test the code.
Now, if your page passes the validation, you will get a “This Page Is Valid XHTML 1.0 Transitional!” message. You will also get a congratulations message. If you want, you can use available options such as Show Source, Show Outline, Validate error pages, Clean up Markup with HTML Tidy etc. and revalidate the page.
If you want to test the current page, the validator.html page’s code will be as below:
<html>
<head>
<title>W3C Web Standard Test</title>
<script language=”javascript” type=”text/javascript”>
function testMyPage()
{
var url = ‘http://validator.w3.org/check?uri=’ + window.location.href;
window.open(url, ”, ‘width=775, height=500, status=yes, resizable=yes, scrollbars=yes, location=yes’);
}
</script>
</head>
<body>
<input name=”Button” type=”button” value=”Test My Page” onclick=”testMyPage();” />
</body>
</html>
What I have done here is — I just changed the webpageLocation parameter to window.location.href.
I must mention one thing and that is you cannot validate i.e. test web standard of any page that is located in your localhost.
Thus, this is very easy but important to validate our pages. I believe validation should be a part of professional website development although it takes some time. But it is a benchmark of the quality of your webpage.
OK. That is all I know.
PHP script to add time. Tutorial with code and example
February 26, 2008
Some days ago I wrote an article on how to get the local time. But I saw that many people are searching with keywords like “PHP Add Time”. As this is happening frequently, I have decided to write an article on how to add time using PHP. Here is the article. In this article, I have written a function that takes hour, minute, second, day, month and year as inputs, adds all supplied time values and returns the new time.
So, you can add hours, minutes, seconds, days, months and years with current time by supplying only 6 inputs when you call the function.
Okay. Here is the PHP function to add time.
<?php
function addTime($hours=0, $minutes=0, $seconds=0, $months=0, $days=0, $years=0)
{
$totalHours = date(“H”) + $hours;
$totalMinutes = date(“i”) + $minutes;
$totalSeconds = date(“s”) + $seconds;
$totalMonths = date(“m”) + $months;
$totalDays = date(“d”) + $days;
$totalYears = date(“Y”) + $years;
$timeStamp = mktime($totalHours, $totalMinutes, $totalSeconds, $totalMonths, $totalDays, $totalYears);
$myTime = date(“Y-m-d H:i:s A”, $timeStamp);
return $myTime;
}
?>
Now we call the function to test the output.
<?php
// Let us first see the current time
echo ‘Current Time: ‘ . date(“Y-m-d H:i:s A”);
echo ‘<BR>’;
// Now let us add 2 hours and 10 minutes from now
echo ‘New Time: ‘ . addTime(2,10,0,0,0,0);
?>
Thus, this is so simple to add time using PHP.
So, I hope the people who were looking for a PHP example to add time and eventually came to my article on how to find local time would get the right article.
You can also download the PDF version of this article from the link below:
PDF version of PHP script to add time. Tutorial with code and example
I was searching for some good osCommerce tutorial articles and/or resources for developers. Actually using osCommerce package, it is easy to create online store quickly. It is an open source and completely free project for all to make an online shopping store. During my searching to several sites, I found a very useful site that offers video flash tutorials and/or training. I think both the online shop owners and developers (if working for maintenance as administrator) can be benefited from these video training pages. Actually these video trainings are more helpful for the online store owners who want to manage their online store built on osCommerce by themselves.
Well.
Here is the link: http://www.demodemo.com/tutorials_osc.html
And you will find video trainings on the following subjects:
1. Installing osCommerce
2. Configuring your store
3. Adding categories
4. Adding products
5. Adding product attributes
6. Configuring currency
7. Adding payment modules
8. Adding shipping modules
9. Configuring sales tax
10. Editing your home page
11. Editing left and right columns
12. Editing your header and footer
13. Creating specials
14. Managing customers
15. Sending out a newsletter
16. Sending out email
17. Managing your banners
18. Backing up and restoring your database
Although the page lists topics like Installing osCommerce and Configuring your store, I would like to recommend the store owners to give this work to a professional site developer(s).
But one thing is important to mention. That is – you can only install the simple looking online store using osCommerce package following the Installing osCommerce tutorial. But to give it a professional & customized look and feel, you need to go to any professional developer. The developer then can changes the skin of the page to make it cool looking.
That is all for now.
AJAX Application Design: Tips & Tricks. Must know issues.
February 12, 2008
The AJAX developers need to keep in mind some crucial points when they are developing and designing applications. These facts are applicable from small to large applications. Personally I believe every AJAX developer should know all these facts for developing more robust and reliable applications. Okay, let us see them now.
The Back Button and Bookmarks are going to break down
The back button of the browser is dependent on the history object. Whenever you browse successive pages, these pages are loaded and browser’s history object saves data so that you can go back. But when you are using JavaScript to control the content and behavior of the page, the back button and bookmarks will not work any more.
So, you may develop and set your own JavaScript back button so that the user can navigate to a previous page.
There are ways to solve this problem although pretty complex.
Use Visual Cues
In most cases, AJAX applications work behind the scene. The application may take long time to load or to process lots of data. In such times, it is hard for the user to understand whether the connection with the server is dead or it is still loading and/or working. The user will feel comfortable if you can use a gif image to show that the application working and/or busy. It is common to use a rotating hourglass until data is fully loaded. You can make it appear until the data is loaded and disappear whenever all data are loaded.
document.getElementById(“loading”).style.visibility = “visible”;
document.getElementById(“loading”).style.visibility = “hidden”;
Instead of a rotating hourglass, you can also keep a blue line creeping from left to right slowly.
Let the User Control the Application
It is meaningless if the user types a wrong word and your application immediately stores it in the database. This may annoy the user easily since every user will want to correct it before it is saved in the database. It is a better way to give the user a way so that she herself can store the data when she is ready to do so. Let the user feel comfortable with your application and do not bug her with too much client server interactions.
Also remember to keep a way so that the users can undo errors they have done.
Test Your Application in Different Browsers
Even the most used two browsers Internet Explorer and Firefox do not handle the same coding in the same way. To make your coding cross browser supported, you need to be careful from very beginning.
After you develop a part and test it using the commonly used browsers or by the browser the application will be used is a good practice. The more browsers support your application, the more robust and reliable you application is.
What would you do if your application does not support Safari browser but the Safari users becomes 30% of all users after one year? Will you code the whole application once again?
I think I should mention an interesting information – Internet Explorer and Firefox users are 96% of all internet users. But this ratio may vary at any time as we all know.
Make the User Notice When Data Changes
Your application may automatically change or load data without consulting with the user. These data can be text, image, background color etc and you can place them in <div>, <span> etc tags. But make sure that you have designed in such a way the user has noticed the change. Suppose that you have changed a color of some text inside a <div></div> tags, you can make the color of the text in such a way that it is noticed by the user. Here is a simple example to make the color red:
document.getElementById(“targetDiv”).style.color = “red”;
Or you can change the background color to draw the attention of the user:
document.getElementById(“targetDiv”).style.background-color = “red”;
So, the message is simple. If your application loads data from the server for the user, make sure that it is noticed by user in a easy way.
Sluggish Browser Problem
AJAX application can be huge and also can consume lots of resources such as CPU processing and memory. In such cases, the browser may stop before all data are processed or loaded and browser may even hang. If you can play carefully in such situations, your application is going to be more robust and reliable.
It is a great suggestion for all AJAX developers that do not use AJAX everywhere rather use it when it is necessary. Some developers use AJAX since it is a new technology. You also need avoid this tendency.
Be Careful in Handling Sensitive Data
Suppose that some users of your application do not want your application to save or store their social security number, credit card information, password etc. But your application automatically stores it in the database or somewhere else. This may be dangerous for you. For any problem occurred from storing information without permission may bring legal and/or other actions for you.
Using JavaScript and client-server interaction, you can store the sensitive data in the database easily. But do no do it all the times. So, it is better if you design your application in such a way that the user herself will send the sensitive data to store whenever she thinks appropriate.
A Backup Plan is always a great idea
There is a very little possibility that your users will be online every time they see your information. They can access your pages being offline or your server may go down during the use of your application. In these cases, your application will crash or face problem if your application is fully dependent on persistent (i.e. continued) server processing. You can avoid such situations by creating a backup plan.
How do you handle the situation when JavaScript is turned off? I mean the user can turn off JavaScript and you need to keep a way so that you application still works.
Also please remember to create a backup plan if there is possibility that the browser gets (or may get) slow in procession lots of data.
Search Engine Optimization (SEO)
Google, Yahoo and other search engines tries to visit all your pages and get contents by mapping. What I mean by mapping is the search engine will first come to any of the page suppose the homepage. Now from the homepage, it will visit all the links (i.e. pages) it finds in this page. After going to the new link, it will read and take the contents (text, image, link etc.) of the page. The process will loop until it does not find any new link.
So, the search engine crawlers will not get your page contents if it needs user interaction which is not possible for the crawler. Thus it is always a better practice to keep a way for the search engine crawlers so that they can map all your pages if you want your contents to show up in search engines.
Here a suggestion is to use <meta> tag in the <head></head> section of your page such as this:
<meta name=”description” content=” AJAX Application Design: Tips & Tricks. Must know issues. “>
<meta name=”keywords” content=”AJAX, Design, Tips, Tricks, Tutorials “>
Avoid Browser’s Cache
Browsers store information in the client machine to reduce browsing time and for some other reasons. This kind of storing is termed as caching and all the files stored are called cache. Internet Explorer is very aggressive in caching. If the browser is showing you information from cache, you will miss the updated information which was changed between your last and current visit. To make your application cross-browser supported, you can follow the follow two easy steps and avoid cache problems.
<?php
header(“Cache-Control”, “no-cache”);
header(“Pragma”, “no-cache”);
header(“Expires”, “-1″);
?>
Now you need to place this code in your PHP script. The above code works only in PHP scripts. If you are using ASP or other server-side language, you need to use equivalent code.
Although the above solution will solve unexpected cache problem in most browsers, it may fail in case of Internet Explorer. So, here is the second solution that will force Internet Explorer to reload the page and show the updated information.
If you add a variable in the URL and set a unique value every time, this problem is solved. You can do it this way:
var targetUrl = “script.php?category=perfume” + “&timeStamp=” + new Date().getTime();
I have used the timestamp variable which is actually meaningless or useless and set a value in such a way that it is unique (or will change every time in other words).
You need to use both the ways.
I wish to update this article with more examples in some later time.
You can also get the PDF version of this article from here below:
PHP script/code to get Bangladeshi and any other local time
February 4, 2008
Often in local projects, the Bangladeshi developer may face problem in finding the local time since often the hosting is done in a server which is outside the country. Moreover, there are many different time formats like GMT, UTC etc. But a developer must use local time if it is included in the client’s requirements. Although a little bit browsing can help to solve the problem, I am sharing the solution with you so that you can re-use the code and save the browsing time. What is the benefit of re-inventing the wheel?
Now we can get the Bangladeshi time very easily if we add exactly only 6 (six) hours with GMT time. There may be other ways. But my solution solves it by adding 6 (six) hours with GMT time. Below is my simple function to get the Bangladeshi time in PHP.
<?php
function ShowBangladeshTime()
{
$hour = gmdate(“H”);
$minute = gmdate(“i”);
$seconds = gmdate(“s”);
$day = gmdate(“d”);
$month = gmdate(“m”);
$year = gmdate(“Y”);
// This is the offset from the server time to Bangladesh time.
$hour = $hour + 6;
return date(“h:i:s A Y-m-d”, mktime ($hour,$minute,$seconds,$month,$day,$year));
}
?>
You can also extract specific section of a time in this following way:
<?php
$dayOfTheWeek = date(“l”, mktime ($hour,$minute,$seconds,$month,$day,$year));
$hoursNow = date(“H”, mktime ($hour,$minute,$seconds,$month,$day,$year));
$minutesNow = date(“i”, mktime ($hour,$minute,$seconds,$month,$day,$year));
$AmPmNow = date(“A”, mktime ($hour,$minute,$seconds,$month,$day,$year));
?>
If you have to play with multiple country times, you can just add a switch case way like this:
<?php
function ShowSelectedCountryTime($country)
{
$hour = gmdate(“H”);
$minute = gmdate(“i”);
$seconds = gmdate(“s”);
$day = gmdate(“d”);
$month = gmdate(“m”);
$year = gmdate(“Y”);
switch($country)
{
case “Bangladesh”:
$hour = $hour + 6;
break;
case “India”:
$hour = $hour + 5;
$minute = $minute + 30;
break;
case “Nepal”:
$hour = $hour + 5;
$minute = $minute + 45;
break;
default:
$hour = $hour + 6;
}
return date(“h:i:s A Y-m-d”, mktime ($hour,$minute,$seconds,$month,$day,$year));
}
?>
It is simple to integrate such kind of simple function, script or code in your PHP class according to your requirements.
You can also download the PDF version of this article here below:
PHP script/code to get Bangladeshi and any other local time
Tour to Dhaka’s two sub-urban areas
February 3, 2008
Tour Date: February 1, 2008
Today’s tour was arranged all of a sudden. I phoned my friend Ahsan for a personal reason and he said me he is planning to visit a place inside Dhaka but not develop part. Although I had some works to do, I instantly canceled my works, accepted the idea and agreed to meet him within an hour.
By 11:00 in the morning, we started our journey for the sub-urban areas. The weather was perfect one for me since it was a typical winter morning with soft and warm sunlight. There was a weak flow of air which was also matching with everything.
First we hired a Riksha (a three wheeler pollution free vehicle commonly seen in Bangladesh) and reached near to PostoGola Bridge. Then we bought some sweets (locally named as ‘ChomChom’) for both of us and got into a three wheeler CNG vehicle. During our crossing the BuriGongGa Bridge over the PostoGola bridge, we enjoyed the river’s calm and cool beauty. Arriving to the other side of the bridge (in Arakol village), we searched for a tea stall and we found a wood & bamboo made stall (“Cha-er dokan” in local language) which was built over a small and narrow canal. We took only tea in that restaurant and flies were active all around us. From the wooden window of the restaurant, we saw a beautiful ‘Kosai’ (local name and English name is Brown Shrike) bird was hunting insects. But before the hunting, the bird pretended that it is enjoying sunlight sitting in a branch of a tree which was at the side of the narrow canal and it would not like to move at this moment. Aha! A professional hunter indeed!
Then we hired a Riksha and started for a very old Mondir (a temple of Hindu people). Or the Buddhist could be owner of this temple and I am not sure who the owner was. After reaching there we found only the “beautiful” tower of the temple. Ahsan said that may be there were other buildings adjacent to this temple tower. But those building were lost in the wave of time. The temple was so ancient that we found it somewhat inclined to the east direction. When we were nearby the temple, we saw a group of beautiful long-tail parrots (Rose Ringed parrot) were flying over our head and over temple with making a chorus of “Chi Chi Chi” sound. My friend Ahsan told me that these parrots live in the holes of the temple and we saw the smart design of holes in the upper part of the temple tower. Some young and middle-age trees are living on this ancient architecture although they looked pale and I guess they looked pale because of lack of proper nutrition. How can such an ancient building provide food to these trees?

Photo 1: The full view of the Mondir tower

Photo 2: Close shot of the Mondir tower

Photo 3: Close shot of the lower part of the Mondir tower

Photo 4: The tower if you see just from the bottom of it and we saw bats taking rest in the dark part

Photo 5: Another picture of inner part of the tower

Photo 6: Close shot of inner wall

Photo 7: One of the small Mondir designs in the inner part of the Mondir
We went under the tower and looked upward. Ah! It was so nice. We saw the semi-dark region of the tower and some bats were sitting on the inner wall of the tower. A marvelous scene! But we also got a very bad smell of stool of the birds and bats although we took it as natural.
We were there for half an hour and several groups of parrots were flying over our head. Ahsan recorded the sweet “Chi Chi Chi” parrot tones in his cell phone. We also enjoyed the sunlight & sweet airflow and saw the beauty of another small narrow canal (“Khal” in local language).
Then we crossed a weak dirty Shako (wooden small bridge) and entered another village (TeGhaRia). Like the first village, there also we say the common presence of goats. May be lots of people are nowadays caring goats as profitable business. Some of the local people were looking to us with little curiosity as we differed in dress up and body language.
During our tour we also saw the simple & easy life leading downtown people, domestic hens, goats and new-born cute little goats. We even saw two goats were sitting on the black pitch road and enjoying sunlight! Vehicles were passing them without disturbing them. We found potato and some other winter crop fields beside the roads. We found people taking shower and washing cloths in little ponds. Beside a pond, we saw a father showing anger on his young son for not coming and/or making late to take shower in the pond water in this winter morning. We saw a white throated king fishers. We changed Riksha several time and every ride was simply fun. Do you know the downtown areas and villages have its own natural smell? You will get it whenever you visit such a place. We did not miss it even.
Thanks to Ahsan for taking some pictures by his mobile phone as I can share them here with everyone.
Overall it was an enjoying tour although short. Ahsan is planning for our next tour to DhoLeshShor river side. Aha! Who knows how interesting & enjoying that place going to be! I am just waiting for that time and even from today.
An interesting thing is our total cost for the whole tour was near to 1 (one) US Dollar!
How to encrypt PHP source code, software or project
December 7, 2007
There is a great software to encrypt PHP source codes. I used this software 2 (two) years ago and still now it is the best one that I recommend to everyone. It is SourceCop. Actually this software is for Windows platform. I found it by searching in http://www.google.com. I found many others also. But after trying all of them, I found this software the best one. This software is small, reliable and easy to use. If you give a little time, you can easily learn how to use this software.
Before we start, you need to download ad install the software. You can download the trial version from here:
http://www.sourcecop.com/download/sourcecop.exe
Now download the software in any location of your hard disk.
Installation:
Step 1: Double click on the executable file (i.e. sourcecop.exe) to initialize installation or you can also right click on the executable file and then single left click on the Open option. Now the installation process starts and you see a window as below. Click on the Next > button.

Step 2: Select I agree the agreement and click on the Next > button.

Step 3: At this point, browse your installation destination by clicking on the Browse button. By default, the destination is in the Program Files. If you want to change any settings, click o the Back > button. If you want to install in the Program Files folder, leave it as it is. Click on the Next > button.

Step 4: Select your Start Menu folder by clicking on the Browse button. If you want to change any settings, click o the Back > button. If you do not want to change this, leave it as it is and click on the Next > button.

Step 5: If you want to change any settings, click on the < Back button. Otherwise, click on the Install button to go ahead.

Step 6: The installation file starts copying necessary files. Please wait as long as it finishes copying files.

Step 7: Click on the Finish button and the installation process is complete.

Step 8: After the installation is complete, a desktop icon of the software becomes visible. It looks like as below:

How to use:
Go to your Desktop and open the software by double clicking or by right click and then click on the Open option. You can also start the software from the Start menu: Start -> All Programs -> SourceCop 3.0 -> SourceCop (in case of default installation). Now you will see the window shown below.

Now I will describe the features inside the PHP Project section.
- Select Source Folder button: Click on this button to link with the folder where you have kept your source codes. Actually these source codes will be encrypted. So, after the completion of the encryption process, file contents will be in new look but with the same functionality. Remember that the source codes inside this folder will be changed/converted/encrypted forever.
- Select Backup Destination button: Use this button to specify where to keep a backup copy of your source codes.
- File Types to Encrypt options: Select one or more of the file types that you want to encrypt.
- Any other extension: If you have written your code in any file whose file type is not like any of the previous types (i.e. .php, .php3, .php4, .phtml, .shtml, .inc), write the extension of that file such as .ihtml. Do not forget to give a .(dot) before the extension.
- Run script only on this IP address: Type the IP address only where you would allow executing your source codes. Actually this is specified when you want to give permission to someone for a single Server test run. You can do this also in case of showing your demo copy.
- Set an expiry date for script: Select a date to specify the time when your source codes will no more execute. This is a nice feature to stop the use of unlimited use of your codes. Be default, the date is a past date. Change it as per your requirements.
- Do not encrypt following files. Use comma to separate more than one files: Type one or more of the files that you do not want to be encrypted. You need to type the filename with the extension such as config.php
- Encrypt button: Now encryption process is ready to encrypt your files linked through the Select Source Folder button. Click on the Encrypt button and wait some time. The encryption process ends and gives you a message that the encryption was successful.
Recommendations and/or Suggestions:
1. It is very important to remember that the Select Source Folder button encrypts the source codes of the folder you link to it. So, you will not find the original code in this folder any more.
2. Do not get confused with the Select Source Folder and Select Backup Destination buttons. If you get confused and encrypt your only copy without a backup, you will lose your code forever.
3. Always use the Select Backup Destination button and thus keep a backup copy of your source code.
Important Notes:
Please remember that the software can take somewhat long time to encrypt a “big” project (i.e. a project with hundreds to thousands of files). So, give enough time to this software to encrypt your entire project. In other cases where the project is small to medium sized, the software encrypts the project’s PHP source codes almost immediately.
In some sites, you can find the full functional crack of this software. But I recommend you use a licensed version.