UltraMega Blog

AJAX Loading Image Generator

I came across this handy online tool that generates animated "loading images" for use with AJAX (or anything else): http://www.ajaxload.info/

You can choose from a selection of styles, set background and foreground colors, click generate, and you have your image. It's a real time saver for AJAX applications, and the best part is that they are free to use for anything!


Reloading Images Using JavaScript

There are some situations where you want to reload an image without refreshing the page containing it. This is especially handy with CAPTCHA images, where you might want to give the user the option to get a new code in case the first is too hard to read.

It sounds simple enough, but then there is browser caching that you need to work around. Fortunately, this problem is easy to solve just by altering the URL of the source, adding a unique string to the end (such as a timestamp) as a GET parameter. Here is a little JavaScript function that will accomplish this:


Creating a CAPTCHA in PHP with GD

A CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a system designed to test if input is originating from a human or a computer. The most common method, which you have probably seen, is displaying an image containing distorted text and asking the user to type in the text. It is difficult for a computer to read it and relatively easy for humans, so it is assumed that a correct answer must have originated from a human. This is a tool used to prevent automated spam.

Anyway, this tutorial will explain how to make your own CAPTCHA like the one below using PHP and the bundled GD image manipulation library. This is the method I use on many projects, and it does the job. Keep in mind that there are stronger CAPTCHA systems available if you want to block the more motivated spammers.


Bypassing Register_Globals in PHP

Register_globals is an option in PHP that automatically turns special variables (GET, POST, COOKIE, etc.) into global variables. For example, $_GET['id'] becomes $id and this can pose a problem if you already use $id as an internal variable. This option is deprecated and defaults to off in current PHP versions, but may still be enabled on some servers.

If you want to be sure your script works with or without register_globals, here is a snippet the you can add to the beginning of your script:

   $globals = array_merge($_REQUEST, $_COOKIE, $_SESSION, $_SERVER, $_ENV);
   $rg = array_keys($globals);
   foreach($rg as $var){

This will unset all variables that match the name in those superglobals, negating register_globals. This should work on PHP version 4.1.0+.


Toggle Display of Page Elements with JavaScript

This mini tutorial explains how to show/hide elements on a web page using JavaScript. There are many reasons why you would want to do this, and luckily it is very simple.

All it takes is changing the display CSS property. Setting display: block; (the default for div tags) makes it visible, and display: none; makes it hidden. The advantage to using display is that other items on the page will move to close the void left by the hidden object.


What is AJAX?

AJAX stands for Asynchronous JavaScript and XML. Many modern websites, big and small, implement this technology in many different ways, but what exactly is it? Here is an explanation in simple terms...

An AJAX application is a web page that functions more like a desktop application than a traditional web page in that it feels more responsive. It works by transferring small pieces of information in the background and updating just the affected area of the page without reloading the whole thing. This not only speeds up web applications and lowers bandwidth consumption, it also increases end-user enjoyability. As AJAX becomes more popular, the gap between the Internet and desktop applications will become increasingly smaller.