Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Name

md5()

Synopsis

    string md5 ( string str [, bool raw_output] )

Although the sha1() function is recommended for checksumming data securely, another popular algorithm is MD5, where the "MD" stands for Message Digest. The md5() function produces a data checksum in exactly the same way as sha1(); the difference is that it is only 32-bytes long. Because sha1() is longer, it is less likely to have a "collision"—a situation where two different strings share the same checksum. However, md5() has a slight speed advantage. Unless you're trying to serve your website from a 386 or have been asked to use a particular algorithm, stick with sha1().

Using md5() is the same as using sha1():

    $md5hash = md5("My string");
    print $md5hash;

Note that if you are thinking that having fewer bits in MD5 makes it less secure, you are correct—but only just. An MD5 checksum is 32 bytes long, which is equal to 128 bits. That is, an MD5 checksum can be made up of 3.402823669209384634-6337460743177e+38 different possibilities, more commonly referred to as 2 to the power of 128. This an enormous number of varieties, and it is quite secure for most purposes.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page