Archive for Articles

Twitter for CodeIgniter

Recently, I’ve been working on an OAuth API (server and client both written in CodeIgniter).  After finishing it, it occured to me that I could just as easily use it for my API as I could for Twitter with a few modifications.

Read more

Currency Conversion in CodeIgniter

Currency conversion for websites is one of those things where there’s lots of solutions, but all of them cost money.  I had to do this some time ago for an international procurement tool and, like most people, we had to use a paid solution.  But it got me thinking – currency data is just a series of numbers and must be published by someone, somewhere…

Read more

Indian Rupee Currency Symbol

I’ve been working on a currency conversion class (will post later) and I came across a problem in displaying the Indian Rupee symbol (र).  Whilst not strictly necessary for what I’m doing, I like to make sure everything works properly so as to avoid bugs later.

Read more

Background Gradients in CSS3 – Including IE

CSS3 is brilliant.  It does a lot of the things we used to have to do by embedding graphics in the browser and, consequently, reduces the amount of HTTP data.  However, as the standards aren’t yet in place, things are still a little hit-and-miss.  One of the most useful one is background gradients.  I’ve got this working in IE7+, Firefox, Chrome, Safari and Opera and I’ll run through them in order.

Read more

MySQL fulltext search wrongly return zero results

One of the best things about MySQL is the fulltext search, which uses some black magic to return a relevancy score.  It usually works a treat, but I’ve come up against a problem which I can’t find documented anywhere.  My problem was that, when performing a fulltext search, it was returning no results despite there clearly being some results it should display.  What was particularly confusing was that I’d got the query working on a table with lots of test data in, but couldn’t get it working on the table I was actually planning to use. Read more

PHP’s ps_file_cleanup_dir Error

One of the most annoying errors you can get is the session_start(): ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) error.  It’s one of those where, as a developer, you instinctively press F5 and then you don’t get it for ages.  This is caused by the Apache/HTTPD linux user not having the permissions to cleanup old session files, stored in /var/lib/php5.

Read more

Calculating an exponential base in PHP

Ok then, this is a very specialist thing admittedly, but no less useful.  I’m currently working on calculating an exponential curve in PHP, which is all fairly straightforward.  But I wanted to ensure that, after 9 iterations, it went to exactly 1.  By guessing I’d gotten it to 1.0004, that would cock-up all the calculations if there were massive figures involved.

Read more

CodeIgniter’s 404 Override Problem

The CodeIgniter 404 Override problem is one of the biggest annoyances I’ve got with the otherwise fantabulous CodeIgniter.  For those of you unaware of the problem (and haven’t seen this forum post), in a nutshell the problem is this.  If you go to a URL where the controller doesn’t exist, it works fine and loads up the override controller and method.  However, if you go to a URL that contains a controller that does exist, it fails to load everything in the $this object correctly.  And worse, if you’ve got a directory, it just throws a complete wobbly, loads nothing at all and goes running off to mummy.

Read more

Abbreviating long strings in CodeIgniter

In the process of keeping websites secure, you can end up with really long strings.  If this is generated in the code and saved to sessions/cookies/database, this isn’t a huge problem.  However, if you need to publish such an encrypted string (for instance, in an account creation confirmation URL), having massive strings not only can be a problem it also looks unprofessional.  Of course, there are plenty of URL abbreviation systems out there (bit.ly and tinyURL.com to name but two), but a lot of the time you want to keep it within your own domain.  This is where my abbreviation model comes in handy.

Read more

CodeIgniter ActiveRecord Order by Field

Following on from my post about how to extend the CodeIgniter database library, I’ve had to to find a way of ordering database results by the values in an array.  This is particularly useful if you’ve got an enum field or have specified values in a particular field and then want to output it in a particularly order.  My magical order_by_field() method solves this problem.

Read more