Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

Hashing is the process of creating an index for a value using the value itself. The index is
called a hash. Sometimes hashes are unique to values, but not always. Hashes can be used
to make fast lookups, a method that PHP uses for keeping track of variables. Other times
hashes are used like encryption. If the hashes of two strings match, you can assume the
two strings match, as long as hash values are unique. In this way you can check
passwords without ever decrypting the original password.


Some of the functions in this section are built into PHP. The others are part of Sascha
Shumann's Mhash library. This library presents a universal interface to many hashing
algorithms. Visit the home site to learn more about it http://schumann.cx/mhash/.


string md5(string text)


The md5 function produces a hash as described by RFC 1321. The function takes a string
of any length and returns a 32-character identifier. It is theorized that the algorithm for
the md5 function will produce unique identifiers for all strings.


Figure 9-5. md5.

string metaphone(string word)


Use metaphone to produce a string that describes how a word sounds when spoken. This
function is similar to soundex; however, it knows about how groups of letters are
pronounced in English. Therefore it is more accurate. Compare this function to soundex
and similar_text.

Free download pdf