kieranbarnes Independent PHP, WordPress & CubeCart Programmer

[Snippet] Formatting an IMEI Number in PHP

Posted on March 4, 2011

Formatting an IMEI number in PHP is reasonably simple. The IMEI (14 decimal digits plus a check digit) or IMEISV (16 digits) includes information on the origin, model, and serial number of the device.

The format of the IMEI is AA-BBBBBB-CCCCCC-D, although it may not always be displayed this way. The IMEISV drops the Luhn check digit in favour of an additional two digits for the Software Version Number (SVN), making the format AA-BBBBBB-CCCCCC-EE

 

[Snippet] Simplified UK/US Date Conversion

Posted on March 4, 2011

One of my major annoyances in PHP & MySQL world is the different formats when working with dates.

US format: mm-dd-yy, UK format: dd-mm-yy and MySQL's date,datetime, timestamp columns yy-mm-dd. How do you cope with them all? I've been working on a rich UI recently which includes the jQuery date picker, by default thats in US format. UK users expect a date in UK format.

Tagged as: , , Continue reading

Using WP-Ecommerce Product Downloads without checking out

Posted on February 23, 2011

I've used WP-Ecommerce for a few clients who required an online catalogue, rather than an online store.

One client required a  custom product display and wanted to print out the product downloads in the single_product.php file. Apparently its not possible as we're using Product Downloads for something other than what it was designed for.

It was originally designed for electronic products, you add to basket, pay and you can download the product downloads.

Truncate a string to the nearest word

Posted on February 18, 2011

Truncating a string in PHP is easy, substr($start,$finish), but its annoying when it truncates the string mid-word isn't it? Here's how I overcame the issue to truncate the string to the nearest word.

This is a modified function found on the PHP site.

Tagged as: Continue reading

Installing memcached on CentOS/cPanel

Posted on November 21, 2010

memcached a (distributed) memory object caching system vital if your running a HA Linux* setup or a web farm. Or even if you need fast as **** caching for an application.

Consider it extra memory for your server, so you can cache more, for example large arrays, SQL queries and other stuff!

* Actually I've discovered there are memcached extensions for Java, C & .NET. Wow, it just grew up!

Tagged as: , , , Continue reading

Mini WHMCS SagePay Terminal Mod

Posted on November 4, 2010

We have a few customers that phone and pay WHMCS generated invoices over the phone - we now use the SagePay Virtual Terminal.
So I added a link on the Client Summary page with a direct link. Simple and silly I know, but kinda useful.

Smarty Security – Stop .tpl access

Posted on August 17, 2010

WHMCS uses the Smarty template engine. Which means your .tpl files are accessible to anyone that knows the path. Quite easy in WHMCS. Whilst not really a major security risk, its bad practise to all these files to be accessed directly.

Add this code into your .htaccess file.

  1. <Files ~ "\.tpl$">
  2. Order allow,deny
  3. Deny from all
  4. </Files>
Tagged as: No Comments

Detecting MIME types in PHP

Posted on January 22, 2010

Detecting MIME types in PHP used to be hellish.

Use the mime_content_type function I hear you say. Returns the MIME content type for a file as determined by using information from the magic.mime file. No, its garbage and thankfully now depreciated.

The PHP documentation suggests we use the Fileinfo PECL extension. I wasted ten minutes of my day trying to make that work. It even comes packaged with PHP 5.3. Still doesn't work.

FreeTDS installation directory is not a FreeTDS installation directory

Posted on December 3, 2009

I recently discovered an error whilst trying to (re)install an older PHP version on a client's server. My client required PHP recompiling with MS SQL support. This in turn requires FreeTDS. Installing FreeTDS is very simple, but PHP wasn't.

Tagged as: Continue reading

CubeCart Tax Classes on Product Page

Posted on November 25, 2009

A client of mine sells a mix of VAT and VAT exempt products via a CubeCart 4 store I setup.

Although CubeCart allows this and calculates the VAT right on the checkout process, it doesn't have any facility to show the customer which tax class the product falls into on the viewProd page.

Annoying.

Page 4 of 10« First...23456...10...Last »