The Dev Notes

Notebook of a Developer

Menu Close

Browser and OS statistics from user-agent strings in MySQL

In most online application you are likely to use third party statistics solutions, but there might be situations where this isn’t possible or where you only want to gather some basic OS and browser information.

There are several ways to approach this. One way would be to analyse the OS and browser of every visitor (for example with the PHP get_browser() function) and save a +1 count in a MySQL table per OS and browser. The advantage of this is that it doesn’t require a lot of space to save this information.

Another option is to save the entire user-agent string of a visitor (for example with the PHP $_SERVER[‘HTTP_USER_AGENT’] variable) and analyse this later. The advantage of this is that you are more flexible in your analytical calculations later on, for example if you only want OS and browser information of a specific group of logged in users. Saving the user-agent string also means that, as new OSes and browsers come along, you can adapt your analysis later on, but the saved information will always be correct. The downside of this is that saving many user-agent strings can build up in data size.

For an online application that only has several thousands of logged in users a year, I chose the last option.

Let’s say you have a MySQL table called ‘loginhistory’ that contains ‘userid’ and ‘useragent’. To make a count of how many times certain OSes occurred in the user-agent strings, I used the following MySQL query:

Read more

Managing a subfolder as a project in Eclipse, Git and FTP

For small website projects, managing the project in the same way as the folder structure isn’t always the most practical solution. Say you have a website called ‘mainwebsite’ and a subfolder called ‘admintool’. You might want to manage the two projects separately but still keep the existing folder structure so that the main website is available as and the admintool as This tutorial runs through the steps to manage these as separate projects in Eclipse, Git and FTP and mentions solutions for the bugs I ran into.

You might only want to apply parts of this tutorial to your project but I found the order in which these things are done, in particular for Eclipse, are very important. These steps are specific to Windows, although many steps might also work in other OSes.

First of all, assure yourself you have a recent backup. A lot can go wrong when restructuring projects, so a backup is essential.

Clean up Eclipse

Start by removing the existing project from Eclipse if needed. Obviously without deleting the files themselves. Right-click on the project in your workspace and click delete. When the project is removed from Eclipse make sure the project files generated by Eclipse are also deleted (you might need to turn on Show hidden files in Windows Explorer). Delete the .settings folder and the .buildpath and .project files.

Read more

Refresh browser on saving Code

Web development usually means a lot of switching between your code and your browser and then refreshing the page to test your changes. The Ctrl+s > Alt+Tab > F5 loop.

To automate this process and make it a little quicker I wrote a short AutoHotKey script. There are other options, and some editors even refresh a browser page as you type, but this worked best in my Windows setup.

Read more

One WordPress in the Root, one in a Subdomain

Running multiple WordPress installation on the same domain has always been a bit chaotic. Even with the improved Network or Multisite feature there are still a couple of things you have to pay attention to. If you also use the same datbase for multiple WordPress installations you want to make sure the wp-config.php files use different prefixes for the table names.

Another issue is the rewriting of URLs when you use subdomains and you also want to use search engine friendly permalinks. I ran into this problem when setting up this blog on an IIS server.

If you have a WordPress installation in the root of your server, have a different WordPress installation on a subdomain that is redirected to a folder and want to use friendly URLs in both installations you’ll want to use a web.config file like this:

Read more

Starting your XAMPP, IDE and browser with one click

Currently, I do most of my coding on a Windows machine that I also use for video editing, photography, gaming, music production, and other things to be distracted by. Because I switch between these activities a hundred times per day, it means that when I want to continue coding on a project I first open up my XAMPP control panel to start Apache and MySQL as a localhost. Then I boot my IDE (PHP Eclipse) and then I boot Chrome in a Developer user profile I created. All in all it’s about 6 or 7 clicks.

I use a separate user profile for development in Google Chrome. This profile is set on ‘Continue where you left off” under settings, so every time I open this browser, all my tabs of the project I was working on will be there. It also means that I can setup develop specific Chrome extensions like a color picker or an on-screen ruler to only this development user profile.

Nothing terrible but when you do this about 20 times a day it’s just nice to be able to do it with one click. From a productivity point of view I’ve also noticed that you’re much more tempted to spend a few minutes coding in between things when you know that everything you left off will be on your screen with one click.

So my goal was to create a shortcut that would simultaneously:

  1. Start Apache and MySQL on my localhost in the background
  2. Start my code editor (IDE)
  3. Start Chrome in my development user profile
  4. Stop Apache and MySQL when I close the IDE

Read more