Fixing Wordpress Scheduled Posts

7th May 2008 - 4 minutes read time

Wordpress has a neat little feature that allows you to write a post and then schedule it to display at some point in the future. This seems good, but it invariably doesn't work on some server platforms and rather than publishing a post Wordpress just counts the amount of time passed since it was supposed to go live. The basic solution to this is to go into the post and click on publish, which can be a pain if you are taking a couple of days off from blogging and want to leave it running.

The problem lies with the functions that convert a scheduled post into a live post which are kept in the file wp-cron.php in the root Wordpress directory. For some reason the Wordpress developers decided to call the scheduling functions using the fsockopen() function available in PHP. This essentially opens a browser session to the wp-cron.php file, just as you would if you browsed to the location using your web browser.

Check Or Uncheck All Items In A Checklist With JavaScript

6th May 2008 - 2 minutes read time

If you have lots of check boxes in a row a handy little usability trick is to allow a user to click on a button and check all of the checkboxes at once. The following function will either check or uncheck all of the check boxes in your form.

Banner Advert Rotation With PHP

5th May 2008 - 2 minutes read time

A normal procedure with banner adverts is to rotate them randomly, but also to display some more than others. Lets say that you had 3 banner adds and that you wanted to display them at different rates. To do this you can use the rand() function to generate a random number that can then be used to see what banner advert will be displayed.

First we generate the random number, in our case it is between 1 and 100.

Obfusticating PHP Code

4th May 2008 - 2 minutes read time

You will sometimes want to make sure that your code is a better hidden from the end user. For example, you might want to make sure that your database password files are completely hidden from prying eyes so that even if your web server is hacked your database server isn't also compromised.

Take the following code, which prints out "Hello world".

echo "Hello world";

You can encode this into meaningless text by using the base64_encode() function.

$code = base64_encode('echo "Hello world";');

This turns the $code variable into the following.

Firefox JavaScript Debugging And Development With Firebug

3rd May 2008 - 2 minutes read time

Firebug is by far the best JavaScript debugging plug-in available for Firefox. I have been stuck on a few problems in the past and Firebug has usually provided me with a reason as to why things are going wrong. In fact when developing for other browsers (like Internet Explorer) I can feel a little blind as there are no debugging tools with the power and features of Firebug. It can allow you to stop JavaScript execution at any time using breakpoints.

Firefox JavaScript Debugging And Development With Firebug

Firebug is important if you are creating AJAX applications as it will tell you about every client/server communication, what headers where sent and what the response was.

Some Common Timestamp Intervals

2nd May 2008 - 1 minute read time

Using timestamps is quite a common practice, but converting them into "real life" times can be a little hard. So here are some common time intervals that you might need.

When To Use .htaccess Files

1st May 2008 - 2 minutes read time

Hypertext access, or .htaccess files, allow you to change the Apache configuration on a by directory basis. However, you should always use the main server configuration file to do configuration changes whenever possible. This is because when Apache is configured to process .htaccess files it looks at every directory underneath the current directory to see if there are any files present, resulting in a slightly longer page load time. Although this might not be noticeable with low traffic levels, at high traffic levels it can cause sites to slow down. You should therefore use .htaccess files only when the main server configuration file (http.conf) is inaccessible.

To increase performance you can use the AllowOverride directive in your top level directory, or any directory who's subdirectories do not use .htaccess files. This will stop Apache from searching through all sub directories.

PSPad - The Free Text Editor

30th April 2008 - 3 minutes read time

Since starting programming I have used a lot of text editors, some have been good, and some have been very, very bad.

One text editor that stands out is PSPad. It is a free text editor for Windows that has lots of features and is very stable. I have been using this for a while now and have seen very little problems. I say "very little" as I once tried to open a 800 megabyte log file and it fell over, which is understandable.

PSPad

It has the following features:

Create A Web Colour Pallette With PHP

29th April 2008 - 2 minutes read time

Use the following bit of code to create a web safe colour table. In order to for the name of each colour to be displayed the background colour array is reversed and used to create the foreground colours. This makes white text appear on black backgrounds and visa-versa, the only problem is that in the middle of the table it will display grey on grey.

Mask Email With ASCII Character Codes In PHP

28th April 2008 - 2 minutes read time

Hiding your email address in an image is the best way of encrypting your email, but if your server doesn't support the GD2 library, or if you don't want to use it, then you might want to look at a different way of doing this.

The easiest way to encrypt your email address is to turn every character into the ASCII code equivalent and use this to display the text in HTML by putting a in front of each character. Here is a function that takes a string and turns it into HTML encoded text.