Skip Navagation

Full On Design

A Web Development & Technology Blog

 

Coding

CAPTCHA Based On Image Orientation

A few months ago 3 Google employees explored an innovative approach to CAPTCHA (What’s Up CAPTCHA? A CAPTCHA Based On Image Orientation). Essentially they suggested that having a user orientate an image into its upright position is easier for users (typing difficult to read text can be problematic) and harder for computers.

Computers find it hard to figure out what this is
A computer finds it really difficult to know if this is correctly orientated.

Here is a version I wrote which to can use on your website.

View Demo Download

This script makes use of jQuery to allow the user to rotate the images and a little PHP to check the image was rotated into the correct position.

Handling Errors In PHP

Handling errors in PHP can be quite a handful at times. Here is a really simple PHP class which I use to manage errors:

<?php
/*
errors class - Helps management of errors in a script.

@version
	1.0
@author
	Mike Rogers (FullOnDesin.co.uk)
@last updated
	03 June 2009
@usage
	You are free to share, modify and use this code for commercial or non-commercial uses.
	Please give a link back (to http://www.fullondesign.co.uk/ ) if you can, but you don't have you.
	You use this at your own risk.
*/
class errors {
	var $errors_data;

	/*
	Add the error from $new_error into an array of errors.

	@param
		$new_error	string The text related to your error.
	@return:
		True - Error has been Added
	@example
		add_error('Username is Incorrect');
	*/
	public function add_error($new_error){
		$this->errors_data[] = $new_error;
		return TRUE;
	}

	/*
		Outputs the errors.

	@param
		None
	@return:
		- A div (ID - error) which contains the errors.
		NULL - No errors
	@example
		echo output_errors();
	*/
	public function output_errors(){
		if(is_array($this->errors_data)){
			// Cycle through the errors.
			foreach($this->errors_data as $error)	{
				$return .= '<p>'.$error.'</p>';
			}
		// Add it to the error div
		return '<div id="error">'.$return.'</div>';
		}
		return NULL;
	}
}

// @Example - creating the class:
$errors = new errors;

// @Example - Add an error
$errors->add_error('Username is incorrect');

// @Example - Return the errors
echo $errors->output_errors();
?>

If you are looking to fully integrate a script similar to the above, there is a really good post regarding the set_error_handler() function on Tinsology ( PHP Error Handling ).

Q&A: Dealing With XML, Telling A Friend They Got ‘Had’

This is a Q&A section where I answer some questions I have been asked.

Dealing With XML

Question: Is there a quick and easy built in function in PHP to convert XML to an array?

In short yet, assuming the XML your trying to sieve through is not too complex the simplexml_load_file() function should be able to handle your needs.

Telling a friend they got ‘had’

Question: A colleague of mine recently went about starting his own .com, unfortunately the Designer/Coder they used was awful (for some reason, they did not ask me as well). Basically they paid (a large sum of money) to have a wordpress blog with a tacky (and invalid) design slapped on top of it. Should I tell them they got ripped off, and if yes how should I go about it?

This is quite a sensitive subject, on the one hand they have been seriously ripped off (unclosed tags is not forgivable), but on the other hand they also may not take too kindly to finding out that their website is about as useful as  a burning boat.

I suggest showing your friend his website in another web browser, generally if the coding sucks it should render incorrectly. Hopefully the little nudge in the right direction should set the ball rolling in terms of fixing the problems. If they don’t fix it (or ignore the problem), their loss.

Building a Print CSS

CSS sheets revolutionized the way websites are managed and created; they essentially made managing the design a piece of cake.

However, many webmasters (and blog lords) forget to add a print sheet (many of the themes for wordpress lack even a simple CSS print sheet). Here is a quick video tutorial on creating a simple print CSS really quickly.

Read the rest of this entry »