Category Archives: Tutorials

Cordova/PhoneGap Installation Guide

Part of my job involves working with PhoneGap/Cordova to build mobile applications from HTML, CSS and JavaScript applications. When it came time to install all of the necessary components, I found it was not as straightforward as it could have been.

I managed to muddle my way through the installation process using bits and pieces of information gleaned from The Almighty Google; here is a break-down of everything I had to do to begin building with Cordova.

Note: This installation guide is relevant to Windows users.

Continue reading

Share Button

SQL Injection – A Primer

One of the most widespread software vulnerabilities to afflict websites is SQL injection. Poor coding standards, lax security and a misplaced belief that scripting languages are inherently secure can open your website up to numerous and potentially damaging attacks.

Over the course of this post, I will cover the main reasons why you should be concerned and go over some simple steps you can take to make sure that your code is secure.

Continue reading

Share Button

Local and Session Storage

With the advent of HTML5, data storage on a user’s local machine is possible without the need for cookies. The localStorage object allows us to store persistent data, in a key-value pair fashion. There is also a sessionStorage object in which we can store key-value pairs, the data for which is cleared when the user closes their browser window.

Continue reading

Share Button

Random SQL Queries

A year or so ago I was given the task of returning rows of data from a MySQL table in a randomised fashion. This in itself is fairly easy but the project which I was working on displays the data in a paginated format so a constantly shifting random data order would not work. The client also requested that the random order should “re-shuffle” every once in a while.

My solution was to seed the random order with a hash of the current year and month concatenated with each row’s ID value. This means that the random order would be re-shuffled on a monthly basis.

The only caveat of this method is that it’s possible for an end-user of the system to be looking at the site at time of shift, messing up their pagination. But then, with a shifting random order there would always be that possibility!

SELECT *, MD5(CONCAT(DATE_FORMAT(NOW(), '%Y%m'), `id_column`)) AS `rand_col`
FROM `table`
ORDER BY `rand_col` ASC
Share Button