Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Description ¶
- string md5 ( string $str [, bool $raw_output = FALSE ] )
- Calculates the MD5 hash of str using the » RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash.
- Parameters ¶
- str
- The string.
- raw_output
- If the optional raw_output is set to TRUE, then the md5 digest is instead returned in raw binary format with a length of 16.
- Return Values ¶
- Returns the hash as a 32-character hexadecimal number.
- Examples ¶
- Example #1 A md5() example
- <?php
- $str = 'apple';
- if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
- echo "Would you like a green or red apple?";
- }
- ?>
- See Also ¶
- md5_file() - Calculates the md5 hash of a given file
- sha1_file() - Calculate the sha1 hash of a file
- crc32() - Calculates the crc32 polynomial of a string
- sha1() - Calculate the sha1 hash of a string
- hash() - Generate a hash value (message digest)
- crypt() - One-way string hashing
- password_hash() - Creates a password hash
- add a note add a note
- User Contributed Notes 13 notes
- up
- down
- 10 radon8472 at radon-software dot net ¶2 years ago
- <?php
- function raw2hex($rawBinaryChars)
- {
- return = array_pop(unpack('H*', $rawBinaryChars));
- }
- ?>
- The complement of hey2raw.
- You can use to convert from raw md5-format to human-readable format.
- This can be usefull to check "Content-Md5" HTTP-Header.
- <?php
- $rawMd5 = base64_decode($_SERVER['HTTP_CONTENT_MD5']);
- $post_data = file_get_contents("php://input");
- if(raw2hex($rawMd5) == md5($post_data)) // Post-Data is okay
- else // Post-Data is currupted
- ?>
- up
- down
- 3 Some ONE ¶11 months ago
- speed of hash('md5',) VS md5()
- 2017-07-14, on a i7-3540M CPU @ 3.00GHz, md5() is slightly quicker than hash('md5',)
- This code takes 2.29 seconds
- <?php
- for($i=0;$i<10000000;++$i) md5("$i");
- ?>
- while this one takes 2.77 seconds
- <?php
- for($i=0;$i<10000000;++$i) hash('md5',"$i");
- ?>
- But in average, less than half a second for 10 000 000 repetitions is a very minimal advantage.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement