An interesting take on the World Cup

Added on: Thursday 8th July 2010

I may be in the minority but I have had no interest in the football world cup - even for the pitifully few matches that England played. However, I'm glad that Spain won last night and I'll tell you why

If you head over to Sitepoint you'll see they've got a sale with a difference.

From the quarter finals onwards, they have chosen 8 of their books - one for each country with the price determined by the outcome of the real football match.

The 'books' making it to the semi finals had their prices reduced to $9.95 and those making it to the finals are now only $4.95.

Those that lose a match go back to their orginal price.

I was interested in the book representing Spain, so after last nights result I can now have it for $4.95.

Now, the question is do I take a gamble on Spain winning the final (in which case my book will be free for 24 hours) or do I get it now before it goes back to its original price...

What a great marketing idea!

Have you actually attached that file

Added on: Friday 4th June 2010

I guess everybody at some time or another has sent an email saying a file is attached but forgotten to attach the file before sending. If you use Google Mail that may be a thing of the past.

I clicked the Send button in my Gmail account just now and got this message come up.

Google Mail warning

Neat - I got interrupted whilst writing it and had completely forgotten about the file I meant to send.

This got me thinking whether it would pick up different variations of content. It works with attached is, find attached and I've attached but File Attached doesn't.

I tried to find references to it on Google or anywhere else but can't. If anyone can find a definitive list of what words or phrases are picked up then let me know.

Google releases a font directory

Added on: Thursday 20th May 2010

Google has just released their font API which allows anyone to embed a variety of fonts into a webpage without any licensing issues.

Currently the directory offers 19 different fonts. An example of one of them is shown below.

This is the Tangerine font

All you need to do is link to the library via a simple stylesheet statement.

<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine">

Then you just use the font within your element styles.

The other advantage of this method is that the fonts are hosted by Google so you don't need to worry about your bandwidth.

Printing forms from Microsoft Access

Added on: Wednesday 17th March 2010

I have many clients who occasionally like to print out a form record from their databases. Obviously they have reports for the information they regularly print out but sometimes its useful to take a 'screengrab' of the current record they are viewing.

The problem is that often although the form is displaying one record it will actually print out all the records in the underlying recordsource which can mean the whole table.

I did a quick search on the Internet and was surprised to find that almost all results suggest creating a report and then using the 'where condition' of the OpenReport method so that only the selected record is displayed.

The question is- is it worth creating a report for every form that you might want to print out.

I was surprised that not one solution mentioned actually printing the form itself.

All you need to do is use the PrintOut method and ensure that it only prints one page. The code behind the button is shown below:

DoCmd.PrintOut acSelection, 1, 1

Where acSelection is the print range and the two 1s are the first and last page to print.

There are other tricks you can use too. All objects on the form have a Display When property - by default this is set to Always but if you set it to Screen Only the object won't appear on the printed page. So for example your print button doesn't need to appear on the print.

The header and footer sections of the form also have a Display When property so you can hide these too on the print out.

Finally, you can change the Page Setup for the Form - for example changing the layout to Landscape and reducing the margins - so that the record fits on one page.

There are disadvantages of course - you'll get all the shading or colour of the form - but as a quick and dirty method it works fine and saves building a report. 

Microsoft Access Search and Replace

Added on: Tuesday 26th January 2010

Although Microsoft Access has a search and replace feature it only works on data within a form or a table. There is also a Find facility within code modules but what if you are looking for something within a form or query design.

Following the change in the VAT tax rate in the UK on January 1st, I was asked to update an access database to reflect this change.

Unfortunately, this wasn't as easy as I thought it would be because the database had obviously had bits bolted onto it on numerous occasions - possibly by different developers.

So there wasn't a single VAT rate stored in a table somewhere - sometimes the rate was hardcoded into the code behind forms or modules, sometimes in the query design and sometimes in a calculated field on a form.

The code was easy enough to update but the database contained hundreds of forms and even more queries (none of which had a name that gave any indication of what they did) so I was faced with opening each one up and going into design view to check for a hardcoded VAT rate.

At this stage I wondered whether I could make use of the little known SaveAsText feature of Microsoft Access VBA.

SaveAsText does exactly what it says - it writes the query or form design out to a text file. Some of the output is fairly unintelligable but I figured it would be easy enough to spot the VAT rate calculation amongst the text.

After a few minutes here is what I came up with:

Function WriteObjects(sFolder As String)
Dim qdf As QueryDef
Dim ctr As Container
Dim intForms As Integer
Dim db As Database
Set db = CurrentDb()
Set ctr = db.Containers("Forms")
For intForms = 0 To ctr.Documents.Count - 1
SaveAsText acForm, ctr.Documents(intForms).Name, sFolder & ctr.Documents(intForms).Name & ".txt"
Next intForms
For Each qdf In db.QueryDefs
If Left(qdf.Name, 1) <> "~" Then
SaveAsText acQuery, qdf.Name, sFolder & qdf.Name & ".txt"
End If
Next
End Function

This uses the Microsoft DAO library instead of Active X Objects but you could adapt the code to use the latter.

For this to work in a project you would have to first add a Reference to the DAO Object library.

Then just call the function with the folder you want to save the text files in as a parameter. You could call it from the Immediate window or else from a button on a form.

The function then loops through all the forms and queries in the database and outputs each one to a text file with the same name as the object.

Notice the line: If Left(qdf.Name, 1) <> "~" Then in the code. This just makes sure that only saved queries are output - otherwise you'll also get all the queries behind combo and list boxes.

Once I'd got my folder of text files I simply used a text editor (PSPad) to search the entire folder for the references I was looking for.

Having examined the search results I could go back to the database itself and make the relevant changes.

PHP and Ajax with special characters

Added on: Thursday 14th January 2010

Here's a quick tip when using Ajax and PHP to output HTML to a browser. If the code contains special characters such as currency symbols you may get unexpected results.

I was recently working on an ajax script to update our CMS shopping cart and noticed some strange behaviour.

The html for the cart is stored as an editable template to allow it to be styled for different sites. The currency symbols are written into the template.

When the page was first loaded the PHP script processed the template and displayed everything just fine. However, when the cart was updated via the ajax script the currency symbols were replaced in Firefox by the FF FD code for a missing character in a font.

I thought at first that by using the javascript escape function to encode the characters or by using html entity encoding in PHP it would solve the problem. Unfortunately, both of these didn't work.

A quick Google search and I found this article on Roshan's Blog.

The solution is to set the character set in the script that outputs the html to the ajax function using the PHP header function (example below).

header("Content-Type: text/html; charset=iso-8859-1\n");

Winter Wonderland

Added on: Tuesday 12th January 2010

I thought I'd put up some images of our part of Dartmoor taken during the recent cold weather.

It is not often that the reservoir at Fernworthy freezes over. It has only happened twice in the 15 years we have been here.

Click the images for larger versions and a gallery view.

Sunset over Fernworthy

Sunset over Fernworthy

Kestor Rock

Kestor Rock

Fernworthy Reservoir - frozen over

Fernworthy Reservoir - frozen over

Another view of the frozen reservoir

Another view of the frozen reservoir

Another view of Fernworthy

Another view of Fernworthy

Moorland Stream

Moorland Stream

Sorting text fields in numeric order in MySQL

Added on: Tuesday 24th November 2009

Here are several ways of sorting text fields in numerical order in a MySQL query.

Normally you wouldn't do this because you will have defined the field as numeric when setting up the table.

However, if you want to create an application with as much flexibility as possible there will be times when you might need this.

I often use it in our CMS because it allows 'user defined fields' in any record type.

The data is stored in an additional table which references the correct record and field.

As all the data for any user defined field is stored in the same table it has to be stored as text in order to allow the maximum number of 'types' of data.

Any validation is done on the input form so effectively you can have different data types.

So an example might be that a 'Price' field is added to the standard content record for listing products (the full e-commerce module has a separate table for products but a small site wouldn't have this) and this would need to be sorted in ascending or descending order.

If for example you had several entries such as 5.00, 10.99, 1.45 and 6.35 then the SQL statement:

SELECT user_value FROM table ORDER BY user_value

would return 1.45, 10.99, 5.00 and 6.35.

There are several ways you can sort this (excuse the pun!).

SELECT user_value FROM table ORDER BY (user_value+0)

SELECT user_value FROM table ORDER BY CAST(user_value, INT)

and

SELECT user_value FROM table ORDER BY LPAD(user_value,10,'0')

All of the above work and I don't think it really matters which is used. I would guess that the overhead is slightly greater for the last two (although an internal conversion probably has to be done for the first one) but I haven't tested them against each other.

Be careful with the last one which in the example above pads each record with zeros until the result is 10 characters long - if the original value is more than ten characters it will get truncated.

Another easy way to resize images

Added on: Thursday 29th October 2009

A while back I published an article on how to use the Send To Mail Recipient feature on a Windows computer to resize a batch of images. This is fine if you have an email client set up on your computer but what if you use webmail?

As I mentioned in the previous article, there is plenty of software around to resize photos but most of it comes with a bewildering array of options.

The other day, I came across a Firefox extension called Shrunked which will automatically resize any photos uploaded to a website.

I like this idea as the resizing is done from within the browser with no need for any additional operations in another program. The only downside is that it works with traditional File Upload boxes which only allow one picture to be uploaded at a time.

To get Shrunked, go to its page in Firefox Add-ons or search Add-ons for resize within the Photos, Music and Videos category.

On this page you will see that Shrunked is an experimental add-on so you will have to tick the box before you can install it. (see below)

Shrunked Installation

Once the Add-on is installed, select Tools - Add-ons from the Firefox menu, select the Shrunked Add-on and click the Options button. (see image below).

Add-ons dialog

There are two tabs on this window, Site Settings and Defaults. Click Defaults and set values for the maximum size of the images and the quality. (see below). 800px is usually OK for a website

Shrunked Settings

Click OK to save changes and then when you go to upload a photo you will see a new toolbar appear above the website window. (see below)

Shrunked Toolbar 

Click Yes and when the image is uploaded it will be reduced in size so that its maximum side will be the value you have set as the default. Note that you will get the Defaults window pop up again when you first upload to a website but you can select the 'Remember my answer for this website' option and you won't be asked again.

By the way, as stated on the site it doesn't save the settings in earlier versions of Firefox but works just fine in 3.5

Death of Snail Mail

Added on: Thursday 22nd October 2009

Is the two day Postal Strike that began this morning the nail in the coffin for the Royal Mail?

I just can't believe the stupidity of postal workers who have voted to strike when volumes of traditional post have been reducing for years.

The service has also seemed to me to be less reliable over the last few years and it galls me when you have to pay a premium to guarantee that something will get to its destination on time.

Nowadays we have email and skype to communicate and both are much quicker than mail. With a printer at the other end a document can be scanned, sent and received the other side of the world in minutes... and its free (barring the connection and line rental).

Many online stores already use courier services in favour of Royal Mail and I'm sure that following this many more will switch.

I can now pay suppliers and recieve payment from clients via BACS so no need to send cheques in the post - although that excuse is becoming even better as the service deteriorates!

Finally, with email marketing producing great returns on investment there is no longer a need for a national postal service.

There is still something nice about getting an unexpected letter through the post but maybe it is now time to say the the post office has had its day.

5 books for the price of 1

Added on: Thursday 24th September 2009

Following their free PDF book giveaway last week, Sitepoint are at it again. This time it is five books for the price of one.

Yes, thats right! Five books in PDF form for .95.

Having bought quite a few titles over the years I can vouch for the quality of the content and there is a wide range of titles covering all aspects of web design and development from fairly technical to the business aspect.

I'm heading over later to get my order in as it is available for one week only.

The hardest part is going to be choosing which five to get!

Get your books now

10 Useful Usability Findings and Guidelines

Added on: Thursday 24th September 2009

I have just read an article on Smashing Magazine website which was fascinating, especially the one about the use of images with faces.

As usual with Smashing Magazine, the article is well written and is packed full of useful information.

What's more there are usually links to several other articles of interest on the topic too that give further information on the topic.

If you are a web developer or designer and haven't found Smashing Magazine yet, I urge you to take a look.

They post articles regularly (I would say on average one or two per day) and I find most are of them contain something of interest to me.

One gripe though and that is that there aren't enough hours in the day to spend wading through the incredible amount of material on the website!

Sitepoint book giveaway

Added on: Tuesday 8th September 2009

You can get a copy of 'The Principles of Successful Freelancing' for free until 14th September.

Head over to Sitepoint to get a free PDF version of this book.

The reason for this giveaway is to get more people to follow Sitepoint on Twitter - but you don't even need to do that - you can simply get a copy sent to your email address.

Having purchased half a doxen of their books I can thoroughly recommend them not only for technical subjects but also marketing and business.

Conditional Formatting in Microsoft Access Reports

Added on: Saturday 29th August 2009

Whilst working on a Microsoft Access project recently, I needed to produce a report with certain fields highlighted in different colours depending on their values. I new I could do this with conditional formatting so I ploughed on and started building the

After I had spent some time on this, I realised that Access only allows three conditions for formatting of cells - presumably because it mirrors field formatting in forms where you have a format for negative, zero or null and positive values.

This was a bit of a blow as I had committed myself to using this method and the report was all but finished.

After the initial panic, I came up with a fairly simple solution that allowed me to use the five different colours that I needed for each field.

All I did was copy the text box control with the three formats and pasted it on top of the original control.

With the new control renamed I then removed the three conditional formats and added the two extra that I needed.

All that remained was to make sure that the new control only displayed if the value in the field matched one of the two new conditions - one line of code in the Detail_Format event.

My conditions were actually based on the value of a hidden field on the report so the code was simply:

Me!field2.Visible = (Me!hiddenValue > 3)

where field2 is the text box containing the formatting and hiddenValue is the hidden control that is the criteria for the formatting.

Both field2 and the original control had the same recordsource so when the hiddenValue was greater than 3, field2 displayed exactly the same data as the original control but because it was on top, it hid the original.

This worked fine and in fact could be extended to use 10, 20 or more conditions just by adding more duplicate controls and using the Format event to control their display.

NOTE: I had thought originally I could have set the Back Style property of the text boxes to Transparent to hide them without using any code at all but because it was the Back Colour property that was being changed in the formatting this didn't work. Changing the Back Colour when the Back Style is Transparent has no effect.

The report itself was quite a challenge in the first place which is why I didn't want to abandon what I had done for another solution. I will publish another article covering the whole report in due course.

Google Calendar API PHP Class

Added on: Saturday 22nd August 2009

I recently wanted to update a Google calendar via the API using PHP. There are plenty of samples on the Calendar API site but they all use the Zend framework which I didn't want to use.

I've been working hard on a new version of the projects module of our CRM package which enables users to create quotes that when accepted are converted into tasks that can then be scheduled on a calendar.

This also creates a timesheet that users can then update on a daily basis and any completed tasks are automatically added to a customers account ready for billing.

As part of this I thought it would be a good idea to add any scheduled tasks to a Google Calendar - mainly because its then easy to sync this with Outlook.

As I said I wasn't keen on using the Zend examples as I don't use the framework elsewhere so I searched for a PHP 'wrapper' for the calendar API.

As is often the case, PHP Classes had just what I wanted. The class I found also used another class for the Curl calls. The only problem was that the requirements stated that PHP5 was needed and the server I was using only had 4.4.

However, after a quick look at the two classes it seemed that all I would need to do was change the public and private variable declarations to just var. This did the trick up to a point but although the first curl call to login to the account worked fine, the attempt to add a new event failed.

After a liberal sprinkling of curl_error calls, I tracked this down to the curl_execute function returning the error: Failed to open/read local data from file/application.

A quick search on Google and I came across a post on MilkHub that solved the problem.

The wrapper class calls curl with POST data to login to the account but then uses HTTP headers to update an event. Apparently if the POST data is empty you should explicitly set the CURLOPT_POSTFIELDS to a zero length string, something the curl wrapper class wasn't doing.

A quick change to the curl class and it all worked fine. The files are included here if anyone else is having similar problems.

Using GROUP CONCAT in MySQL

Added on: Thursday 30th July 2009

Yesterday I had the need to get a list of unique values from a MySQL database where the values were stored as a comma delimited set. There were several ways to approach this but I wanted to try to minimise the amount of processing required.

Good database design says that it would be better to store the values in a table that links the value to a record in another table - allowing multiple values for each record - but I was stuck with the current arrangement so had to make do.

The particular field in the database could contain a single value such as item1 or multiple (comma separated) values in any order such as item2,item1 or item1,item3

The first thing that occurred to me was just to retrieve the records in question and then use PHP to loop through each one, splitting them into individual values. The code would then add the value to an array if it wasn't already in there or ignore it if it was. Finally it would need to sort the array.

This only involves a single call to MySQL but there is still a lot of processing for PHP.

I then decided to make use of the GROUP_CONCAT function in MySQL as follows:

SELECT GROUP_CONCAT(items ORDER BY items SEPARATOR ',') AS items

This produces a single row with a field containing a comma separated list of all possible combinations eg. item1,item1,item3,item2,item1 from the example above.

By making use of the array_unique function in PHP there are only three lines of code required to create the unique sorted list.

$ary = explode(",", $items);
$tags = array_unique($ary);
sort($tags);

I am assuming in the above code that $items is the value of the field resulting from the MySQL query. The script then uses explode to create an array of values - array_unique removes any duplicates and the sort function ensures they are in alphabetical order.

Wild River Cold Stone

Added on: Friday 24th July 2009

I went to see a screening of this new Chris Chapman film about Dartmoor last night and it just reminded me how lucky I am to live in this part of the world.

Two years in the making the film by Dartmoor photographer Chris Chapman and film maker Kate King charts the history of Dartmoor and its people.

It features some stunning shots of the landscape and lots of local people, many of whom we know well.

If you live on Dartmoor and haven't seen it, the 'roadshow' has now ended but it will also be shown at Dartmoor National Park Authority's High Moorland Visitor Centre in Princetown from 24 July as part of an exhibition about the making of the film.

...and you can buy a copy of the film from Chris Chapman's website.

Improvements in web typography

Added on: Wednesday 15th July 2009

Up until now, if a web designer wanted to use a certain font on a website they either had to play safe and use something like Times New Roman or use JavaScript and Flash to change the fonts when a page is loaded.

With version 3.5 of Firefox it now looks like these techniques are no longer required as all the major browsers now support font linking - a method of using fonts hosted on a web server.

This means that it is no longer the fonts on the users browser that determine how a website looks. Previously if the user didn't have the specified font on their computer then it would be substituted with a standard serif or sans serif font.

Some browsers have supported font linking for some time. (Oddly Internet Explorer was one of the first albeit requiring a proprietary format). The problem though has been one of copyright.

Most of the fonts you can download from the Internet have some form of licensing restriction so that you can't just load them on to your server and link to them.

I have just been alerted to the Open Font Library which has a selection of licence free fonts that can be downloaded and used for websites. They also encourage linking to the fonts on their site.

The good thing is that it just requires a declaration in the CSS file so many CMS systems can use this technique without any changes.

One problem I mentioned earlier is that with Internet Explorer you can only link to fonts that are in their proprietary EOT format.

However, Microsoft provides a free tool to convert True Type fonts (only works on Windows systems though)

Finding the position of a record in MySQL

Added on: Saturday 4th July 2009

Normally when retrieving records from a MySQL database you loop through the results and perform an operation on each in time. The other day, however, I simply wanted to get the position of a certain record in a set - nothing more.

Many people say that the actual position in a result set is meaningless because it depends on the sort order and other factors.

To a certain extent this is true but consider this scenario:

Our CRM application allows you to scroll through groups of records and keeps track of which record you are on even if you go to other pages and then come back.

It also features a navigation bar to allow you to move forward or backward through the set.

As it uses session variables these will be cleared once you've logged out and rather than using database storage I just wanted a quick way to jump to a certain record in the set.

A dropdown list of all records in the set works fine for small sets but the overhead of loading this is unacceptable for very large sets.

Instead I wanted users to be able to find a record in the database and then be able to jump to scroll mode at the position of that record in the set.

I could have simply pulled all the IDs from the set and then looped through them in php until a match is found for the current record but I was sure there was a way to get the position of a record using MySQL alone.

It turns out there is and the code is something like that shown below:

SET @C=0;
SELECT C FROM (SELECT @C := @C +1 AS C, [recordID] FROM [sqlStatement]) X WHERE [recordID] = Y;

Where C is your counter, [sqlStatement] is the SQL to retrieve the IDs (ie [recordID]) in the order that you want them and Y is the ID of the record you want the position of.

Note that this requires two calls to MySQL so if you are using PHP you'll find you have to make them separately as mysql_query doesn't support multiple queries.

Dont let Outlook mess up your emails

Added on: Wednesday 24th June 2009

There is a move going on at the moment to try to get Microsoft to remove the Word rendering engine from Outlook 2010. Whats more the campaign is being mounted using Twitter.

Back in Outlook 2003 (I think it was) Microsoft suddenly took a backward step and started using Word's rendering engine to display HTML emails.

All of a sudden many emails that looked perfectly good in earlier versions were totally different and in many cases unusable (as forms didn't render at all).

Although its been a slow journey to get all the major web browsers to support similar standards we are finally getting closer with the release of IE8.

The same can't be said of emails though - we are still using table based layouts and its very much a case of the lowest common denominator when it comes to features.

If you are a web designer or IT Professional you should definitely tell Microsoft to move forward rather than backwards.

But even if you just use email to keep in touch with customers you should also care because ultimately you want your emails to look the same whoever is reading it and you don't want to spend hours and hours testing each one.

Head over to Fix Outlook to voice your disapproval at this move. (NOTE that you will need a twitter account)

The site background shows all the Twitter users who haved 'tweeted' about it and also has an excellent example of how an email looks in Outlook 2000 and Outlook 2010.

Getting news feeds via email

Added on: Saturday 6th June 2009

Although most blogs and larger websites have rss news feeds it is thought that only 3% of computer users are familiar with how they work.

So an astonishing 97% of users aren't using feed readers to get up-to-date information from their favorite sites.

...and more importantly they aren't getting YOUR updates.

Feed My Inbox is a service which allows anyone to subscribe to any feed and get notifications sent to their email address.

Once you have confirmed your address an email will be sent each time the feed is updated, but no more than every 24 hours.

Website owners can also add a simple form to their sites to allow their feeds to be received by email.

I've added one to this site so you can try it out!

Restricting API usage on websites

Added on: Thursday 4th June 2009

It seems any web application worth its salt nowadays must have an API that developers can use to create mashups or display content within their web pages.

There are various ways that these APIs can be called from a web page - PHP users can use the CURL library - but the most common is an AJAX call via javascript as this can be used on any web page as long as the browser has javascript turned on.

The problem with the javascript option is that the call to the API is exposed on the page for anyone who wants to see.

This might be fine if your API is only for displaying content and doesn't allow interaction with a database but you still might want to restrict the usage so as not to overload your servers.

One of the most common ways to do this is to get users to register and give them a 'key' to include in any call. Your server then validates this key - in the case of Google Maps (version 2) the domain of the calling website is also checked to make sure the key hasn't just been copied from somewhere else.

A search for options on securing API calls brings up this method amongst several others but I haven't yet found a good article on how to put it into practice.

I am rolling my own API at the moment for our Contact Management Software and needed a way of protecting client data by ensuring that only registered websites use the API.

I initially thought of using the server variables exposed to PHP to check the originating site but that didn't work - probably because there are several redirects before the authorisation script.

Then I got thinking that there must be a way to do it with mod_rewrite.

I was already using mod_rewrite in order to set up a clean REST style url for calling the API and I wondered if there was anyway I could pass the calling page url to the script. It turns out there is.

mod_rewrite allows the use of variables to check for certain conditions and you can use the HTTP_REFERER variable in a condition to check if the user has come from a certain page.

I then thought that it might be possible to pass the value of this variable into the rewritten url and so make it available to the checking script.

In fact its easy and it works just include the variable within curly brackets and prefixed by the percent sign and it will then be part of the query string passed to the page.

eg http://www.slowducks.co.uk?d=%{HTTP_REFERER}

Its not foolproof as it can be spoofed and its not always available but my API will never be as popular as Googles (sadly) so I can handle the support issues.

PHP functions and varying numbers of arguments

Added on: Friday 29th May 2009

There are times when you want to pass an unknown number of arguments to a function. A simple example might be a function to add a list of numbers.

At this point I can hear people shouting - 'to do this you just pass a single parameter that is an array of numbers to add'.

In fact this is what I thought I could do for a bit of code that I needed to add to our content management system but it didn't work.

The problem was that I was using the php function call_user_func_array. This function has two parameters, an array containing the class and function to call and a second array with the function parameters.

I mistakenly thought that the call_user_func_array function would pass the second parameter as an array to the nominated function but it doesn't.

If the function being called has one defined parameter then call_user_func_array passes it the first item in the array and ignores the rest.

There is an easy way around this using the func_num_args and func_get_arg php functions.

In the case of adding a list of numbers the code within the function would be:

for ($i = 0; $i < func_num_args();$i++) {
      $return = $return + func_get_arg($i);
}

Just remember not to specify any parameters in the function definition.

Ordnance survey maps on your website

Added on: Thursday 28th May 2009

I've recently come across an application from the Ordnance Survey that allows you to embed maps on your website much like the very popular Google Maps.

The difference is that the mapping used is from the Ordnance Survey which has much more detail than Google Maps.

In all other respects this looks to be very similar to Google's application - you need an API key which covers a single domain and they quote usage limits of 30,000 map tiles of data and 1,000 place name lookups a day.

The service offers maps covering England, Scotland and Wales and you can place any kind of information that has a geographic reference on top of the Ordnance Survey maps and interact with a map - pan, zoom in and out, add markers and polygons.

It all sounds very exciting. Just need to learn the API!

Expect a post here soon with details of how I get on with it.

For more information see the OS OpenSpace website.

Dartmoor Showcase Day

Added on: Thursday 14th May 2009

I had a great day out yesterday when I was exhibiting at the Dartmoor Partnership Showcase Day.

The event, held at the lovely Two Bridges Hotel, was organised by the Dartmoor Partnership which used to be the Dartmoor Tourist Association.

Membership has now been opened up to all trades and services based on Dartmoor and yesterday more than 50 exhibitors came together to show what they can do.

The was an excellent opening address from Malcolm Bell - chief executive of South West Tourism - and throughout the day there were others talks and demonstrations.

Above all though it was a good chance to network with other local businesses and meet new people.

If you have a business based on Dartmoor and aren't already a member of the partnership I would thoroughly recommend it.

Short URLs

Added on: Saturday 9th May 2009

URL shortening services such as tinyURL have been around for some time now. Originally developed to overcome the problem of links wrapping over several lines in email clients they are now more prevalent because of social media applications such as Twitter

With only 140 characters per 'tweet', if you want to include a link to your website or an article on another site you don't want the URL to take up most of the message.

This is where URL shortening services like tinyURL can be useful. It is no longer alone however. A quick Google search shows there is no shortage of other services.

The top 4 services used on twitter are tinyurl.com, bit.ly, ustre.am and cli.gs.

Each of these tries to offer something unique over the other. For example a short url on tinyurl is 25 characters long and on bit.ly it is 20 characters but yet another service r.im offers short urls that are 14 characters long.

So if you need to squeeze an extra few characters into your message then r.im could be for you.

Is this the only reason for choosing a URL shortening service though?

For me there are two other essentials

  1. To be able to track clicks on a URL
  2.  To be able to use an API in order to create the shortened URLs.

Many of the current services do offer both of these features and there is one that I've found - tr.im - that even has the statistics available through their API.

Usually the API is very simple - you tack the URL you want to shorten onto a URL for the API and the return value is the shortened URL.

For example for tinyURL the address is:

http://tinyurl.com/api-create.php?url=[[url]]

where [[url]] is the URL to shorten. In fact it works both ways - if [[url]] is a tinyURL (ie shortened URL) it returns the original URL.

We've now wrapped several of these APIs into a function call and made a Widget to shorten URLs in our CMS.

Of course it is not difficult to create your own URL shortening if you have access to a database and server side scripting.

  • Create a table in the database to store the original URL and a unique ID for this URL.
  • Add some server side code to take a URL and check whether it already exists in the table - if it does, grab the unique ID - if it doesn't create a new record then grab the unique ID.
  • Replace the original link with a link to a new page (with a short name like link.php) and pass as a parameter the unique ID.
  • This page then looks up the original URL associated with this ID and redirects the browser.
  • As an added bonus the page can also record visits to the page (and hence clicks on the shortened URL).

You can even go further and add a userID field to the table so that each unique ID is now for the user/URL combination meaning that you can track clicks by individuals.

For more information, contact me using the contact page.

Of course unless you've got a very short domain name in the first place you are never going to match any of the above services but you will have more control.

Google Static Maps

Added on: Monday 20th April 2009

Google Maps have been around a long time now and have been integrated into numerous websites and applications but in some cases are overkill.

A little while back Google released their Static Maps API which basically takes a set of parameters and generates a 'static' image of the map.

This requires no javascript at all so the solution is ideal where you want a lightweight page or where users might not have javascript turned on.

On the downside you can't interact with the map - zooming, panning or clicking markers but in many cases there is no need to.

For example, on many websites the Contact Us page may have a standard Google map - but is that really necessary? All you need is a marker on the map at the location of the office or premises - no one wants to zoom in or out and any additional information (directions etc) can be supplied in the narrative os there is no need to click on the marker.

We've now added Static Maps as an option to the Maps module in our content management system and this page advertising the Chagford Two Hills race shows it in action.

Unfortunately at the moment it is not possible to add customised markers but I think that will probably come.

jquery form validation and IE6

Added on: Friday 17th April 2009

The validation plugin for jquery is a simple way to add sophisticated validation to any forms on your website. However, I recently had a problem with IE6.

The validation on the website I was working on was fine in Firefox and Opera and indeed Internet Explorer 8 but in IE6 the Submit button went straight to the next page without checking the form.

I noticed there was also a javascript error just before the page submitted.

A quick search on Google took me straight to the jQuery Validation website where I quickly found that this was a problem with the character encoding of the page.

It seems that if the character encoding is set to UTF-8 then there is a regular expression in the javascript that throws IE6. If the character encoding is ISO-8859-1 then all is fine.

The suggestion to resolve this was to track down the expression and removing the offending characters. However, as I was using the packed version of the file, I couldn't use this so I installed the unpacked version instead.

Obviously in the unpacked version the code is different as the validation worked fine in all browsers that I tested.

To summarise then - if you are using jQuery validation and your character encoding on the page is utf-8, use the unpacked version of the script.

I thought I'd post this as it saved me hours of messing around. And thanks to those before me who have found the solution to the problem.

Reading Publisher Files without Publisher

Added on: Friday 10th April 2009

I was recently sent a file containing a poster design to put on a website that I look after. The only problem was that it was a Microsoft Publisher file and I don't have Publisher on my computer.

Well I do have a copy of Microsoft Office on CD but I am loathe to install a program I hardly, if ever, use just to open a single file.

Other programs with proprietary file formats such as Word have a free viewer available and are also so widely used that many other progams can read and write to them.

However, it seems that Publisher isn't. A search on Google revealed solutions ranging from 'it is not possible' to an article on Microsofts' website showing how to load the file into Microsoft Document Imaging and save it as a tiff file.

Again this latter solution involved loading a program that I would seldom use - so I wasn't interested.

After looking at several technical forums it seems that there isn't another program that will read a Publisher file.

Then I found the link to convert to pdf. This is a beta online application which does 'exactly what it says on the tin'.

It couldn't be simpler - you point it to your file (there is a 6MB limit) and then click the Convert button. I uploaded a 100kb file and it was ready to download or email in a matter of seconds.

The list of supported file formats is extensive and includes Word, Excel, Powerpoint and Publisher as well as WordPerfect, OpenOffice and StarOffice and several image file types.

A PDF file may not be the ideal solution but for me it was fine as all I needed was to extract some of the text and have it as a download.

Flexible working

Added on: Monday 6th April 2009

An amendment to the Flexible Working Regulations issued by the Department for Business, Enterprise and Regulatory Reform comes into effect today.

The right to request a flexible working pattern will be extended to cover employees with parental responsibility for children aged 16 and under.

There are other criteria they need to fulfill such as having worked for a company for at least 6 months but effectively this could mean changes for employers, especially if they haven't got the IT infrastructure to deal with this.

However, at its simplest, all that is required is an Internet connection to provide email communication with the office and for those that have it a secure VPN.

This is where SAAS (software as a service) applications come into their own as everything you need is online already.

Further information:

A CRM solution for flexible working.

Famous at last

Added on: Thursday 26th March 2009

A quote I made after a networking event last year has been picked up and used on the advertising material for this years event.

Network Central 09 has been jointly organised by 14 networking organisations and is billed as the largest networking event in the South West of England.

I went to Networking Central 08 in Plymouth last year where there were over 500 business people and filled in a questionnaire afterwards.

My quote now appears at the top of the website for this years event and on all the flyers. Unfortunately there is no direct link to my website but I am seeing an increase in visitors searching for Round Ash Associates

It just goes to show that sometimes you can get a boost from unexpected quarters but I still firmly believe that networking is one of the most effective ways to do business. I have been a member of the Business Network for a number of years now and it has really helped me to increase awareness of my products and services within the local business community.

Register for Network Central 09 and I'll see you there!

13 Reasons you should Embrace the Web

Added on: Friday 20th March 2009

A website design company in Australia has created this simple site to show people (or remind those that know) why the Web adds value to any business.

Have a look and see whether your company is reaping all of the benefits of the Web.

If not, then as the site says, you need to contact your web company.

Geotagging website content

Added on: Thursday 19th March 2009

It seems that nowadays every site must have a map to display content. Whether its a business search facility, a store locator or a list of attractions on a tourist trail users expect to be able to find information using maps.

It is easy enough to add a map to a website and display content (see a previous article on the Google Map module for our CMS) but you can only do this if the content has spatial data associated with it.

It is possible to convert a zip code or UK postcode into the latitude and longitude required for Google Maps but this is usually done in an external application and its a tedious job to copy and paste these coordinates back into your own application.

Also, especially for UK postcodes the conversion isn't very accurate in rural areas and my own postcode plots about 10 miles out on the map.

Another alternative for the UK is to convert an Ordnance Survey map reference to WGS84 latitude and longitude but this requires the reference to be more accurate than the standard six figures.

No, the most reliable and simplest way is to find the location on the map itself and mark it directly.

Having added the map module to the CMS, I thought that it needed an easy way to geotag any content on the site so I set about integrating a point and click method for positioning any data.

All content is added via a form and to keep things clean I decided the map should pop up rather than be inline which would take up too much room.

Geotagging data

The map is opened via the '...get position' link.

My favourite 'pop up' window isn't really a pop up at all but is the excellent thickbox which uses the DOM to display a window on a new layer. This in itself caused me a few problems trying to get the map to load into this window. However the article at dropstones helped me solve these.

When the link is clicked, the script loads the map into a hidden div an the thickbox tb_show method is called using the inline option to pull the content from the hidden div.

Google map in pop up window

The map has the usual controls so that you can zoom in for better accuracy and once a point is clicked on the map the lat and long fields on the form are updated.

So you can now add position information to any content on your website and I've set this up as a special field type so that the boxes and pop up link automatically appear on any form that requires a location field.

The code used for the process is contained in this text file.

A decent travel search engine

Added on: Wednesday 11th March 2009

You've been there before - select your start point and destination, enter the dates you want to travel on and the results page says sorry there are no flights/ferries on that day.

It really frustrates me when I am trying to book transport on the Internet and the website expects me to know beforehand which days the flight or ferry or bus goes on.

The other annoyance is when you want to get the best deal by looking at other travel dates and you have to search through each day at a time.

OK, more sites nowadays give you the option to search a day or two either side of your chosen date but you still get the feeling that they don't really want you to find the best option.

Having spent years developing search engines on various database driven websites, I've often thought that it isn't difficult to show the user a variety of dates and time for their journeys and even price options based on the search parameters.

Well, I was pleasantly surprised the other day when I came across Skyscanner. This has to be one of the most user friendly travel search sites I have seen.

Right from the beginning they give you as much information as possible. Click on the Whole Month option on the front page and the search results are displayed as a bar chart with days of the month along the bottom and prices up the side.

You can then see at a glance which days there are flights to your destination and how much they will cost.

There is more though, hover the mouse over one of the bars and it gives you the departure and arrival times and the airline.

Even the destination dropdown box is colour coded with green for direct flights and red for indirect.

You can also select a departure airport and a destination airport and see which airline (if any) flies direct and which airlines offer indirect flights.

The whole interface is really slick and uses AJAX (I guess) to update in real time.

I haven't yet gone through to the airlines website to check the accuracy of the prices and to make a booking but will definitely be doing this soon.

Google Maps

Added on: Friday 6th March 2009

Since Google released their Google Maps application and the API to allow developers to add maps on their own sites it seems that nowadays a website isn't complete without an interactive map.

All the bigger open source CMS applications now have a Google Maps plugin and I thought it was time that our CMS offering did the same.

So, I'm pleased to say that there is now a new Map module within our CMS that allows users to create their own maps and display them on any page.

With it you can set the default zoom and centre point for the map and then add markers by clicking on the location and filling in the details on a form.

There is also the ability to add lines and closed shapes to a map - again by clicking the points on the map.

Markers can also be associated with content already stored in the system so for example you could add a marker for all photographs in an image gallery or show the locations of events.

Any markers that are added are stored separately to the maps so that they can be used on any map without having to add them again.

Currently this only produces an interactive map but I'm working on a facility to create a static location map (image only) for use on contact pages etc.

Heres a link to one I made earlier (screenshot below) for Accommodation in Chagford.

Accommodation in Chagford

The power of jquery

Added on: Wednesday 4th March 2009

With the recent rise in popularity of online applications and the subsequent drive to create rich user interfaces comes a host of powerful javascript libraries.

There are now numerous javascript libraries available to help simplify the more mundane tasks involved in writing your code.

I'm not going to recommend any particular library over another but as a developer I've decided to pick one and stick to it rather than trying to use the best features from each of them. This is a practical approach as I simply don't have the time to learn the syntax for each of them and keep abreast of developments.

I'm also not going to get into why I eventually chose jQuery but suffice to say that at the time it seemed to have everything that I wanted for the sort of projects I was working on.

Anyway, if you haven't looked at jQuery yet then it might be worth your while because once you get to grips with the syntax, I promise you it will take your javascript to new heights.

I'm writing this because yesterday I revisited some code (originally written with jQuery) for an application where I wanted to enhance the usability even further.

The application is based on our CRM software but has a module that creates a seating plan for members going to monthly lunch meetings.

The client is a networking organisation so one of the rules is that where possible no members should sit with someone they have sat with before. The software automatically checks back a certain number of lunches and tries to place people according to this rule.

It also takes into account any specific seating requests from members and ensures that no two people from the same business category are on the same table.

Once the calculation has been done the administrators are able to go in and use a drag and drop interface to make any final changes and this is where jQuery comes in handy.

Although there is a warning message whenever a person is dragged to a table and the resultant move violates any of the above rules, I wanted some visual feedback when the mouse hovers over the person to be moved.

To do this I got the server side PHP to create a table of which guests have sat with each other. When the page loads, the ids of each of the people a person has sat with are added to the class for the html element for that person.

So a typical class might look like class="2401 345 6750..."

I then created an 'over' class (red border) and got jQuery to apply this class to each element containing the class corresponding to the id of the element the mouse is over. The code is below:

$("li.block").mouseover(function(){
var el = $(this).attr("id");
$("."+el.addClass("over");
});

Just 4 lines of code (and thats to make it easy to read!) and all the people who have previously sat with a person are highlighted on the mouse over event.

(There is a corresponding mouse out event as well to remove the highlight).

Following some comments from users who said it would be nice to know not just that two people have sat together but also how long ago this was. I initially thought that this might just be something that pops up in the warning message rather than on mouse over but after a bit of thought I realised it was quite easy.

I altered the PHP code so that in addition to storing the ids it also stored how many lunches ago the two guests sat together. As the page loads this number is appended to the id and separated by an underscore so the class now looks more like - class="2401_2 345_1 6750_2..."

I then created the classes for the number of lunches ago that the clash occured - simply over1, over2 etc.  These could be styled with different borders or backgrounds but I've chosen to add an image of the number on the right hand side of the element.

The revised jQuery is just:

$("li.block").mouseover(function(){
var el = $(this).attr("id");
for(i=0;i<6;i++){
$("."+el+"_"+i).addClass("over"+i);
}
});

I'm sure this can be streamlined further. I think I can probably remove the for loop and use the jQuery each function but I'm still learning and this does the trick at the moment.

Pretty powerful stuff though and it just shows how easy it is to add some impressive functionality to your application.

Uploading images to a website

Added on: Tuesday 3rd March 2009

If you maintain a website using a content management system then uploading photos to the site is one of the trickier tasks to do.

Many content management systems only allow you to upload one picture at a time - mainly because of the size of the files involved.

If you can import several files at a time then either you have to sit and wait while they are all uploaded or you need to get to grips with FTP software so that you can transfer the files directly to the server.

Following the article on resizing photographs on your computer before uploading them, our content management system now has the option to email these files straight to your site.

A dedicated email address is created for each site and this email is checked every time someone logs into the site administration area.

If there are emails then a message appears before the summary screen showing the subject of the email and listing any attachments. For each email there is the option to Process or Delete (if the email looks suspect).

Note that when the emails are processed any which don't come from a registered email address are ignored.

The Process page shows all the images in the email and at this point you can select which ones to keep, add a caption to each one, create a small version of each and also add them directly to an existing list (gallery) on the site or create a new list.

Process Uploaded Images

This is a much more efficient way of uploading photos to a website gallery and I'm going to look at this method when working on my paperless office.

A global telephone directory

Added on: Saturday 28th February 2009

From 24th March everyone will be able to register a .tel domain. This new top level domain is very different to all the others that are currently used though.

The idea of the new .tel domain is that it is used to store contact information for companies or individuals.

You might argue that this is already done by having a website on any of the other domains.

The difference though is that you won't need a website as the details are stored directly in the DNS. You can think of this as similar to doing a whois lookup at the moment - the owner, admin and technical contact details are all stored against this record.

With a .com or .co.uk domain for example when someone requests a URL the DNS looks up the location of the page and this is then loaded into the users browser.

The .tel domain doesn't need to forward you to a slow loading website but simply loads all the contact information for that company or individual into your internet enabled device (it could be a mobile phone or palm top device).

So what are the advantages in this? It is being touted as a single point of  contact for a company or individual enabling them to publish all their contact details such as telephone numbers, fax numbers, email addresses, website links etc and also include location information and keywords for search engines. In short a global directory.

Will it work? As with any directory or listing it will only really be useful if it is taken up by the majority and there seems to be little or no hype relating to it at the moment even though priority registration has been available since early December.

Also, as of the time of writing you can't access any .tel domains from a web browser and a google search on companies such as IBM or even Google itself doesn't present a .tel result.

It seems as if most people are waiting to see what will happen before they jump on board and at the moment its just another 'must have marketing tool' being forced on them.

The difference though is that it will use the DNS system which is the backbone of the Internet so it is tried and tested technology which so far has proved extremely reliable.

I must admit that I will be watching this closely as I like the idea of a single, easily updatable point of contact and if it is universally adopted it will revolutionise the way we get information. Whether it will replace the likes of Google, Facebook etc as marketing tools is another debate.

Internet Explorer reserved word problem

Added on: Wednesday 25th February 2009

I was working on an update to some software the other day and while it worked fine in Firefox and Opera it kept throwing up a javascript error in Internet Explorer.

I am always hopeful that one day there will be a time that you can create a web application knowing that it will look and operate exactly the same across all browsers without the need for extensive testing in each one.

Unfortunately this won't happen soon so for the time being we are stuck with applying fixes for the various shortcomings and vagaries of modern browsers.

To cut a long story short, when I finally tracked down the error it had nothing to do with javascript at all.

The problem appears to be that I had an element on the page that I had given an id of 'tags' (because I was updating the tags field for a record via AJAX).

Simply changing the id of this element to something other than 'tags' solved the problem, so it seems that this is probably a reserved word for IE.

It was only afterwards that I did a search on Google (probably because I didn't know what I was looking for initially) and found some references to javascript print errors to do with an id of 'tags'. 

Your website and the law

Added on: Tuesday 24th February 2009

Besides the obvious one of making sure you own the copyright (or are licensing it) on all content on your website there are several other issues you need to be aware of - even on the smallest website.

I went to an interesting seminar last week that discussed the legal issues involved with setting up and running a website.

In addition to copyright, you will need to think about disability discrimination - (can disabled users get access to the same material as anyone else?), data protection - (are you processing personal information on your site - the answer is probably yes!), email marketing - (do you have an opt IN policy and not an opt OUT for anyone signing up to receive newsletters or other correspondence?) .

You also need to make sure that there are contact details somewhere on the site and for companies the registration and VAT numbers should be displayed.

See these sites for more information:

Information Commissioners Office

The Privacy and Electronic Communications Directive 2003

Web accessibility

A hidden gem in PHP

Added on: Friday 20th February 2009

One of the most common tasks when developing websites or online applications is date manipulation. You might for example need to create a list of memberships due to expire within the next month.

Of course PHP has plenty of date/time manipulation functions you can use but there is one called strtotime (string to time) that is very underrated.

The description in the manual says - Parse about any English textual datetime description into a Unix timestamp

A timestamp is simply a numeric representation of a date and it is this value that can be used to compare two dates or add a number of days, weeks, years etc.

I have been using strtotime for years but up until recently it was mainly to convert dates pulled from a database (as they are retrieved as strings).

If I wanted to work out the date in a months time I would use mktime. For example:

$dt = mktime(0,0,0,date("m")+1,date("d"), date("Y"));

This is not too complicated but it still has three other function calls (to date()) within it.

Consider however this alternative:

$dt = strtotime("next month");

A bit simpler, eh?

As the description says you can use just about any English textual datetime description. I tracked down a reference giving some information on the date input formats but essentially you can use common phrases such as 'Monday', 'next week', 'last year', '1 month', '1 day ago'.

By default the function calculates the timestamp from the current date and time but you can also include as a second parameter a timestamp from which to calculate the new date from.

I discovered this whilst looking for an easy way for users to add tasks to our contact management software. I wanted a way for people who were away from their office to be able to add a task or reminder by email from their Blackberry or iPhone.

This had to be as simple as possible - the email is sent to a specific address with the due date of the task or reminder in the subject and the details in the subject.

I thought a nice touch would be to allow users to put tomorrow or next friday in the subject and I thought I'd have to write a function to process these into dates - but then I discovered that it was already done. Fantastic!

Screen capture of web pages

Added on: Wednesday 18th February 2009

Have you ever needed to take a screen grab of a web page you are viewing? You can press the Print Screen button but if you want to edit anything you have to load it into your image editing software.

There is an excellent tool called Fireshot available as an add on to both the Firefox and Internet Explorer browsers.

One of the best things about it is that it enables you to grab the entire page in one go even if it scrolls off the screen.

There are also some fairly sophisticated editing facilities built in that allow you to crop the image, add annotations and apply other effects.

One I use all the time is the blur tool. I can quickly take a copy of a web page and obscure any sensitive information before emailing it or uploading it to the web.

A built in email button converts the capture into an image and attachs it to an email - what could be easier. And if you do need more powerful editing options you can save it to a file and load it into your main image editing software.

Here's one I made earlier (of adding this article to my blog)

Fireshot screengrab

Visit the Fireshot site for more information.

Database Conversion

Added on: Friday 13th February 2009

If you find yourself frequently moving data between different types of databases then you can either write a script to do it or you can use one of the many utilities available.

I've been converting a lot of Microsoft Access databases to MySQL recently as customers want their software applications to be available online.

Although I have developed a script that I can use to do this it is a bit rough around the edges and I haven't had time to refine it at all so I usually end up with quite a bit of additional tidying up to do on the data.

So, the other day I thought I'd see what was available on the Internet. In the past I've tried various programs but have always found them lacking in certain areas (or not working at all).

To my surprise though I found a piece of software - Access To MySQL - by a company called Bullzip

Unlike a lot of other utilities it doesn't try to be clever and only does the one type of conversion but that is all I wanted.

I have to say I am really impressed - its very simple, fast and more or less foolproof. As well as all this the software is Freeware so may be used free of charge for non-commercial purposes.

I will do some more testing but it looks like this might become a valuable tool for me.

Fantastic Book Offer

Added on: Wednesday 11th February 2009

If you want a good deal on books about web design and marketing take a look at the fantastic offer on Sitepoint at the moment. But HURRY its only on until this Friday.

As the owner of half a dozen Sitepoint titles, I can vouch for the fact that all their titles are very informative and of a high standard.

Their offer is for 5 books for the price of 1. These are PDF downloads and Sitepoint are giving 100% of the sale proceedsto the Australian Red Cross Victorian Bushfire Appeal.

So hurry over to take advantage of this time limited offer. I know I will be!

Video screen capture

Added on: Tuesday 10th February 2009

If you ever need to record a video tutorial of something on your screen then this great online application is the ideal tool

Screen Toaster is a FREE online video screen capture tool. It is fairly basic but that means it is easy to use.

Once you have created an account you just click the Record link and it downloads a small applet onto your computer.

Once this is installed a dialog pops up and when you click Start Recording you have five seconds to get to the page you want to record.

You can use audio and subtitles but at the moment there is no way of exporting the file with either of these options so the video has to be hosted with screen toaster.

There is an option to upload to youtube but this is still experimental and doesn't work that well.

Anyhow, I'm going to be exploring more as I am wanting to create video tutorials for our content management system, contact management software and email marketing package.

For now though here is my first attempt at using this software:

Resizing Photographs for your website

Added on: Thursday 5th February 2009

Most modern digital cameras nowadays have very high resolutions which means that the photos are larger than most computer screens let alone web pages.

Even when displaying larger pop up images from a thumbnail in a photo gallery you only need a resolution of 800 x 600 pixels - unless perhaps you are selling photographs online in which case you should have some sort of watermark to prevent downloading.

Although many website content management systems allow you to resize images via the administration area, you still have to upload the file first and with typical sizes of 3+MB this may take some time.

Try to upload half a dozen or so together and you'll probably be timed out or be told you've exceeded the maximum file size.

There are lots of tools around that can be used to resize images on your PC but most of these come with a huge number of options to rename the resized images, save or overwrite the original etc.

Here is a little used way to easily resize a group of photos in Windows without any additional software. The method below describes how to do this in Windows XP but Vista will be similar.

Firstly, go to the folder with the photos in and select the ones you want to resize. Once the selection is complete click the right mouse button on one of the photos and select Send To > and then Mail Recipient.

Emailing Photographs

A window will then pop up options to make the photos smaller or keep at the original size. The Make all my pictures smaller option is selected by default.

If you click the Show more options... link at the bottom of the window you will see a list of three sizes - Small, Medium or Large. Small is the default but Medium is also OK for websites.

Photo Sizes

Select the size and click OK. This then generates a new email message with the photos as attachments.

At this stage there is no need to send the email (although you can of course use this option for sending to other people) but you can simply select File > Save Attachments... from the menu in your email software.

Select a new folder to put them in and you now have a set of photos resized ready for your website.

So, how do you get them on to your website? Well thats the subject of another posting but our content management system has a secret weapon that makes this very easy!

Sorting photos by date taken

Added on: Wednesday 4th February 2009

I had a bit of a disaster last night whilst trying to get all my digital photos into a web based gallery and needed a quick bit of code to fix it.

The gallery uses a MySQL database and has a facility to index new photos that have been downloaded into a new folder.

Once the images have been indexed by the database they are moved from the download folder and renamed to match the reference in the database.

I made a stupid mistake when using this and managed to rename all the existing photos so that they no longer matched the database reference.

Not a major problem you might think as it is easy to write a quick php script to rename all the files in a folder.

However, the database also contains metadata about the photos and the new filenames no longer sorted into date taken order as they would have done when first indexed.

Exif to the rescue

Luckily, php has a set of functions to extract the 'exif' data from a digital photo and using the read_exif_data function I was able to get the 'DateTimeOriginal' value for each photo.

It was easy enough to load these into an array, sort them and then loop through the array and rename the files.

So 10 minutes later I had my photo gallery back to the state it was in before I messed it up.

I've put the code in a text file for use by anyone who wants to do this.

Is your software weatherproof

Added on: Tuesday 3rd February 2009

As some parts of the country experience the worst winter weather for 20 years can your business cope if no one can get into the office?

Car in snowUnlike North America or other European countries, a little snowfall here seems to disrupt the entire transport system.

This means that many people can't get into the office so businesses are running at reduced capacity or in some cases not at all.

However, with the increasing availability of broadband connections and web based software many companies are now able to operate from anywhere with access to the Internet.

Obviously, if the business relies heavily on transport and delivery or needs key workers in the field then this isn't going to help but much of the administration could still be done online.

It is much easier than you might think to put your existing system online and our online contact management software has many of the features needed already included as core modules.

And because its modular the only customisation required is for specialised areas of your business.

As I sit here writing this the snow is once again falling heavily outside but I don't have to go anywhere!

A font with holes in

Added on: Monday 2nd February 2009

A company in Holland have come up with a new font that they say will save on ink costs by cutting down the printable area on each letter.

The font called the Ecofont is similar to the Verdana font but each letter has a series of holes in it - thus in theory requiring less ink.

However, many people have said that although the font is freely downloadable, the quality of printed documents that use it is not good enough for publication.

So what will it be used for? Printing out internal emails and memos?

Although the company should be applauded for the idea shouldn't we really be encouraging people not to print emails in the first place?

That's why we are constantly developing our online contact management software so that the information is available to all users without having to print it.

You can find out more about (and download) the Ecofont here.

The all important follow up email

Added on: Friday 30th January 2009

This week I returned from a weeks skiing holiday in France and yesterday I got an email from the company I purchased my travel insurance from asking if everything went OK.

Firstly, the email (with the subject 'Welcome back from your holiday') started off by thanking me for purchasing the insurance.

There then followed a paragraph that contained all the information needed if I wanted to make a claim.

Finally they offered me a discount on any future purchases and some advice on the types of policy available.

This is a great example of good marketing for the following reasons:

  • They are selling to existing customers.
  • They know I have been on holiday and when so the subject of the email is more personal - and I'm more likely to open it.
  • The email contains useful information that I would otherwise have to find myself making me more interested to read on.
  • Once my attention is grabbed it then goes on to try to sell me more products.

This sort of thing is very easy to do as long as you have the information - in this case dates of the policy and customer contact details.

What's more it can all be automated so that you can concentrate on other tasks.

There are plenty of other areas where this can be used. For example if you provide accommodation then you could have a system to send out an automatic email after the holiday asking for feedback and you could also email the customer at the same time the next year reminding them that it was a year ago they booked and how about another holiday?

If your system can't do this them perhaps you need to get in contact?

Remember its much easier to sell to existing customers (provided they had a good experience previously!)

Page has expired

Added on: Thursday 29th January 2009

On many websites with search forms, if you do a search and then go to another page to view the results, clicking the back button brings up a 'page has expired' message.

You can of course hit the Refresh button but many people want to go back to the page and have the original search criteria - perhaps you want to view each result in turn.

I've tried various ways in PHP to do this by changing headers etc but the single line of code that works perfectly every time is as follows:

header("Cache-Control: max-age=300, must-revalidate");

The max-age is in seconds so the above keeps the page 'alive' for 5 minutes. You can change this as you like.

RSS Autodiscovery

Added on: Wednesday 28th January 2009

RSS autodiscovery is a technique that makes it possible for browsers and other software to automatically find a site's RSS feed.

I found the following article on how to add RSS Autodiscovery to your site when I noticed that a feed on one of my sites wasn't coming up whilst using the search facility in Google Reader.

I had been testing the various ways of subscribing when writing a previous entry in this blog on using RSS feeds.

Within a day of adding the relevant code to the home page of the site in question the feed appeared in the search results!

Needless to say our CMS now has autodiscovery written into it by default. See the source code for the home page on this site.

Using RSS feeds

Added on: Wednesday 14th January 2009

How to get information sent to you rather than having to go out and find it.

An RSS feed is used to publish frequently updated information such as blog entries and news headlines in a standardized format.

It includes full or summarized text, plus other data such as publishing dates and authorship.

These feeds are great for readers who want to subscribe to updates from their favourite websites.

RSS feeds can be read using software called an RSS reader, feed reader, or aggregator, which can be web-based or desktop-based.

A standardized file format allows the information to be published once and viewed by many different programs.

The details below show how to subscribe to and read a feed using Google Reader but the process is similar for most feed reading software.

1. Open up Google Reader

If you haven't already got Google Reader then first of all go to the Google home page. At the top left of the screen you will see some options. Click on the more link and select Reader.

The next screen will ask you to sign in to your Google account. If you haven't already got a Google account then click the Create an account now link below the sign in panel.

Once you have created an account and logged in then you'll see a Reader link listed under the My Services heading. Click this link to open Google Reader.

Google Reader

2. A quick guide to the reader

The left hand panel shows the number of unread items and a list of current subscriptions.

The right hand panel shows the  unread items under the heading A look at what's new.

To read an unread item, click the item title in the list in the right hand panel.

Reader Item

This will open the article in a new window.

3. Subscribing to an RSS feed.

More often than not you will subscribe to an RSS feed from the site you are visiting (if there is an easy way to do it) rather than from within Google Reader.

On most sites with RSS feeds you'll see an icon similar to the following:

RSS Subscribe buttonorRSS Subscribe icon

The page you see when you click on the icon will vary depending on what site you are on but what you want to look for is some reference to Google or Google Reader (see below)

Add RSS feed

Clicking on Add to Google displays the following page:

Add To Google Reader

Click the Add to Google Reader button and you'll then be asked to sign in to your account. Once you've done this, the subscription will display in the left hand panel of Google Reader and you'll see a list of items (initially all marked as unread) on the right hand side.

To subscribe to a feed from within Google Reader you either need to know the full address of the feed (feed url) or hope that it can be found from a search.

RSS Add Subscription

If you enter the feed url you will be automatically subscribed to the feed. If you enter a search term you will be presented with a list of results with a Subscribe button next to each one.

4. Getting the latest news without logging in to Google Reader

Google Reader saves time by 'pulling' new articles and announcements from various sites without you having to visit each site to find out whats new but you still have to log in to Google Reader regularly to get this information.

I have added the Google Reader Gadget to iGoogle so that when I go to Google to search for something my unread articles display on the same page...but thats another article!

Further reading:

Google Reader for Beginners

Spam filtering in online forms

Added on: Saturday 10th January 2009

I have several enquiry forms on some reasonably high traffic web sites and I have been getting a daily bombardment of rubbish from spambots automatically filling in these forms. One of the forms even has CAPTCHA on it but this isn't very effective.

I came across this great article on reducing the amount of spam in online forms the other day and thought I would try a few of the techniques myself.

So the other day I implemented the following (in the order below) on one of my forms.

  • Hidden form element - The form now includes a text box (hidden using CSS) with an explanatory label in case it does display. If this is filled in during the form submission then its likely to be spam.
  • Detection of  suspicious code - this checks the submission for the [url code which signifies that someone is trying to include links to other sites.
  • Detection of multiple links - this checks the number of times a hyperlink is used within the form. If more than three are detected then this is likely to be a spam entry.
  • Detection of keywords - we have all had the emails or form submissions that include links to the more dodgy sites so you know the sort of words I'm talking about!

The PHP script that processes the form submission checks for the above in the order listed and adds some text (SPAM) followed by the reason (one of the methods above) to the subject of the email. For the time being I'm only monitoring these submissions so they are still coming through to me but I'm pleased to report that it seems to be extremely effective with all the suspect emails correctly identified.

I'll continue to monitor for a while and then change the script so that it doesn't let any spam emails through.

However, we've already written the hidden field into the form building routine of our Content Management System.

Picture of Andrew ParrottAndrew Parrott runs Round Ash Associates, a web design and development company based in Chagford on Dartmoor, Devon.

If you prefer updates via email then please enter your email address below and click Submit.

Email:

Powered by Feed My Inbox