Articles about PHP

PHP is a server-side scripting language designed for web development and a very popular one. It powers many of the popular websites that had became part and parcel of our lives.

In this page, you can find articles on PHP references, PHP coding and application setup.

Connecting to and disconnecting from a MongoDB server in PHP

The first step to manipulate data in the MongoDB ecosystem is to connect to a MongoDB server. In php, we can use the Mongo class to help us connect to one or more MongoDB servers.

For the purpose of this demonstration, let’s assume that we had installed a MongoDB server instance as a windows service which listens on port 12345. In addition, our PHP web server runs on the same machine as the MongoDB instance.

Make your PHP webpage loads faster by aggregating external CSS scripts

In most cases, the speed of which a browser completes the rendering a of webpage is very much dependent on the network connection which connects it to a web server. While some browsers have the luxury of fibre connections, there could be others that are rendering your webpages via a mobile network.

Because each HTTP response consists of the header portion in addition to the actual content, we could reduce the number of bytes that our browsers need to read from our servers by aggregating external CSS and JS scripts.

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 http://www.techcoil.com/robots.txt.

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.

Generate PHP codes with PHP

Throughout my programming years, I observed similar trends in code structures and I felt that being able to generate them automatically will greatly reduce development time.

Although there are many code generation software on the web, coding one for your own usage can be simpler and more convenient, especially when you had written custom functions that your generated codes will utilize.

In this post, I shall discuss my recent experience in creating a PHP code generator for my own usage.