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.
Archive for PHP
Twitter for CodeIgniter
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…
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.
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.
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.
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.
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.
Advanced Email in CodeIgniter
Sending emails is one of the biggest challenges for a website. As well as making sure they’re secure, you want to ensure that no emails get lost. Since the British Companies Act 2006 made email a legally-recognised form of communication, you also want to ensure that you know what is being sent out in your name. The biggest problem I’ve had is where a script has died when it should have sent an email (usually caused by the pesky Sendmail) and just leaves users waiting for their emails ad infinitum. I’ve also had times where the server has had a limited number of emails it can send per day/hour. This is my attempt to solve these problems.
Extending the CodeIgniter Database Class
In the CodeIgniter user guide, it says that the Database class can’t be extended. Which is a real pain, because it would be useful if it could be. Well, lo and behold, the user guide is telling fibs. The Database class can be extended. And, what’s more, it’s fairly easy and is not a nasty hack either.
CSV Output in PHP
Comma separated values (CSV) files are a really useful way of outputting data to display in spreadsheet programs such as MS Excel. However, they can be a bit tricky to output and get all the headers output. So, here’s a simple class to do it.



