archives for: October, 2011

Posted by: bob on Monday October 17th 2011 2 comments
Tags: extension, geoip, php

During the past few weeks I have been working on a brand new PHP extension to provide an easy object oriented interface for the GeoIP library from MaxMind. The original module (that I did not write) had two main issues. First the directory to find the databases could not be changed except in PHP.INI before PHP loads (so not even ini_set would work). Second was that it was old school and not object oriented. Another issue (so that really makes three) is that it will throw E_WARNINGS for dumb things like records not being found. If there is no record found when you ask for it I would much rather just be handed a FALSE.

[update 2011/10/26] Official GeoIPo manual/documentation is here.

This new one is nearly complete, but I am still waiting to be accepted into PECL. However it works and I have the source available for use on GitHub. Here is a little how-to on how to set up the GeoIP database and use this module.

Why use GeoIP?

  • Perhaps your project has support for English, German, and Polish languages. With GeoIP you can try to guess what country your visitor is from and if they are from a country with a language you support you can set that language default for the user. Things like that go very far towards user experience.
  • If you have a website, I doubt many people can honestly tell me they are not curious what country their visitors are from. GeoIP is an important part of determining your reader demographics. You know all those maps that show dots about where visitors are from? You need GeoIP info to do that.
  • And the bane of all internet users – lets say you are the owner of YouTube/Spotify/iTunes and you need to prevent a certain country from viewing/watching/listening to specific content because of license restrictions. You are going to piss people off, but I guess for legal reasons it just needs to be done.

These are only three of the many valid reasons you might need GeoIP information. Over here I have a page demoing the readout of the server and visitor’s GeoIP info, with a link to the visible source at the bottom.

Continue reading about setting up and using php-geoipo

Posted by: bob on Friday October 7th 2011 no comments
Tags: development, evolution, framework, php

From explosm.net
from C&H explosm.net

For the past  year one of my side-not-so-side projects has been the zen\this Framework. Technically the project is even older than that. It was started because many years ago I wrote a Database library for MySQL that I really liked. It wrapped mysql/mysqli into what I consider a much more common and better interface. At the time it was designed to be portable to any codebase and handle things like injection protection without me or the other developers (who were at the time, interns) spacing about it. When I decided to write additional libraries the design challenge was to mimic the original design pattern of that database library.

The interface was quite simple. The main database class was a series of static functions, and there was a query object class too. This was before we had namespaces in PHP so the main database class was really just being used as a namespace. Configuration options were placed in a static array, database::$config, and most of the functions referenced that when deciding which database to query as it handled multiple connections.  This worked great as a completely stand alone library but after it evolved into the current edition in zen\this there have been some design issues.

Continue reading about the evolution of that database library…