PHP codes to tell browsers to open the download dialog box for users to download a file

Ideally, when we build web applications which generate files on demand, we will want our users to be able to use their browsers to save a copy of our files in their local harddisk. For instance, the tool for generating customized codes for countries in the world, which I had created earlier, will tell browsers to prompt a download dialog box after users had submitted the form.

Image of firefox dialog box after submitting request to generate custom codes from list of countries in the world.

However, this is not the default behavior of browsers. By default, browsers will show the contents of a HTTP response generated by our PHP script in the browser window. This behaviour can be seen when I point my browser to

In this post, I will discuss how we can tell browsers to show a dialog box for users to save the contents generated by a PHP script as a file.

A simple tool to encode text for HTML

Part of my job scope as a Systems Analyst at ANZ is to create form applications for business to generate leads. There are times when business stakeholders gave me paragraphs of terms and conditions to include in my form applications. Thankfully, these paragraphs are usually formatted nicely in Microsoft word documents.

However, because these paragraphs are intended for humans to read, special characters are not presented in html entities.

To utilise my web hosting to the fullest, I had created a tool that help me encode such paragraphs for web browsers to render.

How to compress and decompress files in C#

Files are useful for applications to communicate with others. For instance, web applications can communicate with Google’s crawlers via sitemaps on the Internet. A web application write urls to its pages to its sitemap. When Google’s crawlers come to this web applications, they will download these sitemaps to index urls to the pages of .

To reduce the time needed for files to be trasmitted over the network, it is a good idea for applications to compress files before sending them out to the network, or for a web application, making them available for download via HTTP.

In this post, I document how we can compress and decompress files via the GZip implementation in C# – System.IO.Compression.GZipStream.

How to ensure that your user only runs one instance of your C# program

There are times when we want to limit our users to run an instance of our C# program at any one time. Such situations can be applicable for network monitoring tools, messaging applications, web server monitoring application and etc. In this post, I discuss how we can achieve that via the mutual exclusive (Mutex) mechanism available in C#.

Handy Javascript code segments

The augmentation of Javascript to CSS and HTML is beautiful. While trying out jQuery to create my own tic tac toe game, I realised that there are Javascript/jQuery code segments that could be helpful to me when building web applications.

In this post, I collate Javascript and jQuery code segments that I had utilized in my web projects for ease of future references.

How to execute codes periodically in C#

While some applications passively wait for files to be available for processing, there are many others that need to periodically execute codes to fulfill business requirements. For instance, some may constantly trigger other applications via the command line to monitor the network while some others may constantly access databases to generate graphical reports for business analysts.

C#.Net is one programming language that you can use to create applications that need to do work periodically, especially in a windows environment. In this post, I document the usage of the System.Timers.Timer class to execute codes periodically.

How to send HTTP post requests and HTTP get requests using jQuery

This was a proof of concept to try out jQuery’s ajax features. Asynchronus Javascript And XML is a way for avoiding unnecessary refresh of the entire web page. When used properly, it can enhance user experience for your website, especially when you have lots of images on your page which does not change often across different pages.

This proof of concept was based on jQuery version 1.7.1.

Code segments for rendering html 4.0 pages

Very often, I find myself creating HTMl pages from scratch. Those could have been situations when I want to try out some javascripts or write some php proof of concepts.

Although there are many frameworks around, I still prefer the pristine way of rendering HTML pages as I can be certain that there will not be conflicting javascripts or php scripts when I need to try something out.

In this post, I put together pieces of HTML codes that I find myself using often. This will make HTML development more convenient as I do not have to wade through the many search results from google to look for them.

How to make your customer helpline less frustrating – insights from experiencing a really bad one

I was at a cash deposit machine with my mum to deposit cash to pay for my dad’s taxi rental. After accepting our cash notes, the machine was not able to record our deposit details nor return back our notes. After printing a receipt that indicate the error and showing a number for us to call, the screen was reverted back to its home screen, ready to service the next customer.

Luckily my mum brought her mobile phone, there are no phones anywhere near the machine for customers to call to the helpline. Dialing 11 numbers got me to connected to an answering machine. There were a few questions that I had to struggle to interpret (due to the nearby noisy market) and some options that I had to select (or not select) in order to get to a human-friendly human.