If you have some type of report which you would like to export into Excel then you can do so by doing the steps below in PHP:

1. Ideally you should create a separate file which should mimic the one you are trying to export into Excel. So suppose the name of your file is reports.php create another with the name of reports_excel.php

2. Do not include any images and CSS in this file as Excel will not recognize it. For e.g. if you need to change the color of the text then do it the old fashioned way by using the font tag and setting the color and size in it.

3. Once you have created the template and layout in the new file add the following lines at the top of the file:

header("content-type: application/vnd.ms-excel");
header('Content-Disposition: attachment; filename=<your_filename_here>.xls');
header('Pragma: no-cache'); 

4. Now if you run the reports.excel.php file you will see a popup which will ask you to open the Excel sheet in your browser or save it on your hard drive.

5. Save the file and open it and you will see all your data is there in Excel format.

A client of the company I work for pointed out a problem in which some how the SSL version of his website got indexed into Google and other search engines.  Now this posed a problem for the client as search engines don’t rank web pages well which can be referenced from two or more different urls.

As the website was in Zencart I knew that there was no option than to write code to effect redirection from SSL to non-SSL url.

So, I opened the html_header.php file present in the includes/templates/<Your_Template>/common folder and wrote the following code at the top:

if ($_SERVER['HTTPS'] == 'on') {
if (isset($_GET['main_page'])) {
$strMainPage = $_GET['main_page'];
switch($strMainPage) {
case 'index':
case 'product_info':
case 'privacy':
$strURL = "https://". $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
$arrFrom[] = "https://";
$arrTo[] = "http://";

$strURL = str_replace($arrFrom,$arrTo,$strUrl);
header("Location: $strUrl");

The above code helped redirect those pages whose SSL version got indexed by mistake into the search engines. If you note from above I have not redirected post shopping cart pages as they need to be running in secure mode so that customer can enjoy safe and secure shopping.

Tagged with: , ,

I had been working on a website based on ASP.NET 2.0 and SQL Server 2005 Express Edition. However I was facing a problem on it. Problem was that the website worked all right during the busy hours such as in the morning and afternoon but in the wee hours of the night the website would hang i.e. website did not give response at all and some how the website used up all the server memory and processing speed.

The problem was peculiar in that it happened when there was no traffic on the website and thereafter it worked fine. I ignored it thinking it might be due to the server maintenance that usually went on at that time however when this started to happen frequently and the client began to lose patience I knew this had to be tackled soon.

So I looked at the SQL Server logs. I found nothing in it. Then I looked at the web server logs thinking some one may be trying to use brute force or DOS attack on the website. I again found nothing.  This started to become confusing.

Out of nowhere I thought why not look at the Event Viewer and surely I saw that the SQL Server database was being closed at some time and then it was opened. I deduced that the time when it was opened must be the same time at which the website did not respond and caused that hanging effect.

I knew that SQL Server had an auto-close feature but this feature was by default unchecked in SQL Server 2000 where as after going through Books Online I found that it was by default checked in SQL Server 2005 due to which I faced this problem.

I unchecked the Auto Close option in SQL Server 2005 and the problem was resolved.

Tagged with: ,

Following tips will help you to make a cross-browser compatible website as all leading browsers such as Internet Explorer, Firefox, Google Chrome, Opera etc are starting to base their markup formatting on W3C standards:

1. Firstly, HTML 4.01 is outdated and the current standard is XHTML 1.0. There are not a lot of differences between the two but what ever differences there are are very important. Please refer to the W3C XHTML standard.

2. W3C also provides a markup validation service which you should use to validate your markup on a regular basis. Chances are that you will face a lot of errors and problems the first time you validate your page but you will learn a lot.

3. It is also a good idea to browse through the W3C CSS standard as that will help you maintain the consistency of the appearance of your page and controls across all browsers.

4. Try to control all your positioning and styling through your CSS and use tables as less as possible.

Hope the above points help you to make better cross-browser compatible websites in the future.

We have all moved databases from one hosting machine to another by creating SQL dumps with PhpMyAdmin or any other mySQL desktop client on the source machine and then running those SQL scripts on the destination machine. This is fine when the size of the database is a few MBs. However when the size is several hundred MBs then it requires some other procedure. Below is one such procedure for moving a large sized mySQL database.

The following technique applies to mySQL database in which all tables store data in the MyISAM format.

1.  Go to the physical location where the mySQL database maintains its FRM and MDY files on the source machine.

2. Download all the files on which the database is based on.

3. Create database with same name on the destination machine.

4. Upload the files which you have downloaded.

5. Copy the files to the location where the mySQL database maintains the FRM and MDY files on the destination machine. PLEASE STOP mySQL SERVICE ON THE DESTINATION MACHINE BEFORE COPYING THE FILES.

6. Start the mySQL database.

You can start using the database as you normally would.

Tagged with:

Job seekers all over the world are trying to land that “better job” than the one they currently have and in the process put in some time exploring the overall job market and whats in and whats not.

Job and career websites have sprung up a lot in Pakistan in the past 2-3 years and many candidates use them to maintain their resume and apply for jobs through them.

Some of the top job websites are as follows:

You can get the latest browscap.ini file from the following website.


After downloading the file you can copy the file to your system WINDIR/system32/inetsrv folder and start using it.

Tagged with: ,

If  you have ever come across form validation in HTML then you will have come across the issue of visitors inputting white space in the form controls and submitting it which does not serve any purpose to the client. Not only that this could also be seen as a potential vulnerability by spammers.

So the best way to go about this is to place validation to check for white space and what better way than to use regular expression for checking it.

You can use the following function to check for white space:

function chkspace(str)
isWhiteSpace = new RegExp(/^\s+$/);
if (isWhiteSpace.test(str)) {
return false;
return true;
Tagged with: ,