next up previous contents
Next: Security Up: CGI Programming in Perl Previous: CGI and Environment Variables

URL Encoding

One of the limitations that the WWW organizations have placed on the HTTP protocol is that the content of the commands, responses, and data that are passed between client and server should be clearly defined. It is sometimes difficult to tell simply from the context whether a space character is a field delimiter or an actual space character to add whitespace between two words.

To clear up the ambiguity, the URL encoding scheme was created. Any spaces are converted into plus (+) signs to avoid semantic ambiguities. In addition, special characters or 8-bit values are converted into their hexadecimal equivalents and prefaced with a percent sign (%). For example, the string

Dave Marshall <dave@cs.cf.ac.uk>

is encoded as

Dave+Marhsall+%3Cdave@cs.cf.ac.uk%3E.

If you look closely, you see that the < character has been converted to %3C and the > character has been coverted to %3E.

Your CGI script will need to be able to convert URL encoded information back into its normal form. Fortunately,

The cgidecode.pl contains a function that will convert URL encoded.

It:

The Perl for cgidecode.pl is:

sub decodeURL {
  $_ = shift;
  tr/+/ /;
  s/%(..)/pack('c', hex($1))/eg;
  return($_);
}

This function will be used in later to decode form information. It is presented here because canned queries also use URL encoding.


next up previous contents
Next: Security Up: CGI Programming in Perl Previous: CGI and Environment Variables
dave@cs.cf.ac.uk