richardoneill.com.au » Homepage

Latest Articles

PHP Command Line Tip

11 September 2007 PHP, Programming

Here's a quick tip for working with the command line in PHP.

If you've ever run a PHP script via the command line, you would have noticed that output from the script is not printed until the script has finished.

If you need your output displayed in real time, you can open a stream to the command line...

$stdout = fopen('php://stdout', 'w');

Simply write any output to the stream and it will be printed on the command line in real time...

fwrite($stdout, "Hello CLIn");

0 comments

Photo of the week: Railway Tracks

10 September 2007 Photography

Railway Tracks

1 comments

Background Noise in CAPTCHAS

28 August 2007 PHP, Programming, Security, Web Design

One thing I keep noticing is the use of background noise or clutter in CAPTCHAS. It's now well known in the OCR (Optical Character recognition) field that background noise can be easily removed by computers. It's basically useless at hindering spam bots.

It's so easy that I was able to clean the following CAPTCHA up in only 20 lines of PHP code.

CAPTCHA

Here's how...

At a glance, you can see the CAPTCHA's background noise has a blue tint. CAPTCHA RGBLooking at the RGB value of the image in Photoshop, I can see that all parts of the background have a blue value higher than 180.

That's the only piece of information needed to remove the background.

The code simply loops through every pixel of the image and checks the RGB value of it. If the blue (B) value is higher than 180, color it white.

Here's the final image. The characters can now be easily separated and identified using OCR software.

CAPTCHA

So you can see why most background noise is basically useless in CAPTCHAS.

2 comments

Photo of the week: Stairs

27 August 2007 Photography

Stairs

0 comments

Basic 3D Engine Design

23 August 2007 Programming, PHP

Ray Casting is a extremely fast method of generating 3D images using high-school level mathematics.

Remember playing Wolfenstein 3-D? This was one of the first games made using the ray casting technique.

Wolfenstein 3d

The graphics in Wolfenstein don't even come close to today's gaming standards; but it was still impressive for it's time. It was also fast, considering the speed of the hardware it ran on.

Although ray casting is an outdated method, it's a good introduction to 3D imagery and game design. It's also quite easy to recreate yourself (if you can remember pythagoras theorem).

The basic idea of ray casting is very simple. To transform a 2d image map into a 3d representation, "rays" are projected from the viewer towards the light source. If a ray hits an object on the 2d map, a vertical line is drawn on our "3d" image to represent this section of the wall or object. Think of the image as vertical slices.

This diagram might do a better job of explaining.

Ray Casting

Textures can be applied using texture maps but unfortunately other effects like reflections aren't so easy to create. They can be faked though.

If you've got nothing to do for a few hours, consider creating a simple ray cay caster in your favourite language.

Here's a few resources to get you started.

0 comments

Photo of the week: NYE Storm

21 August 2007 Photography

This was the storm from new years eve 2006, about 5PM.

NYE Storm

0 comments

Facebook Code Analysis

16 August 2007 PHP, Programming, Security

Facebook Code Analysis

Most developers have now heard about Facebook's leaked index.php source code, which was anonymously posted here. If you haven't seen it already, there are a number of links listed on Techcrunch.

I've seen a few bloggers criticize Facebook developers for using procedural programming rather than classes and object oriented techniques. I'm not exactly sure why they've chosen to develop the site like this; but I am going to take a guess and say it was to improve speed and efficiency.

Object oriented programming was first introduced to PHP in version 4. However, the language wasn't originally designed around objects and classes, so the implementation was clunky and awkward. This meant that procedural code was often much faster than object oriented code.

Considering the size and popularity of social networks, I'm not surprised they chose procedural code over objects. That tiny boost in performance would easily outweigh the advantages of using classes.

Fortunately, most (if not all) issues with objects have been solved in PHP 5, which is now closer to a truly object oriented language.

0 comments

Photo of the week: Floodway Garbage

13 August 2007

Floodway Garbage

0 comments

Check Username Availability

8 August 2007 Programming

The goal of a signup form is to quickly convert visitors into registered users. The easiest way to increase your sign up form's conversion rate is to lower the amount of time it takes to complete.

One way to do that, is to add a "check username availability" feature. Users will often choose conflicting usernames, especially on large community websites.

Rather than reporting the error on the next page, give the user a quick and easy way to check their username availability. This will speed up the sign up process.

As always, start with your interface. A simple form with a text box, a div, and a "Check Availability" button is all that's needed. You can copy the HTML from the demo.

Check username availability

Using the prototype javascript library, we will send an AJAX request to a seperate checkuser.php page, which will print either 1 for "available", or 0 for "not available". Our javascript function will print the appropriate message in our div, then highlight the textbox with green (available), or red (not available).

Here is the checkUser() javascript function. Don't forget to include the Prototype Javascript file.


function checkUser(user)
{

  var url = encodeURIComponent('checkuser.php');
  var params = 'user=' + escape(user);

  new Ajax.Request(url, {
    method: 'get', parameters: params,
    onSuccess: function(transport) {
      if(transport.responseText == 1){
        $('userstatus').innerHTML = 'Your username is available.',
        $('user').style.backgroundColor = '#caffd5'
      }else{
        $('userstatus').innerHTML = 'Sorry, that username is already taken.',
        $('user').style.backgroundColor = '#ffd4ca';
      }}});
}

View the Demo.

This is only a small way you can increase the effectiveness of your sign up form. I will be writing about other methods in the near future.

2 comments

Photo of the week: Floodway

6 August 2007 Photography

Floodway

0 comments

Canberra Web Design