Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. Description ¶
  2. string md5 ( string $str [, bool $raw_output = FALSE ] )
  3. Calculates the MD5 hash of str using the » RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash.
  4.  
  5. Parameters ¶
  6. str
  7. The string.
  8.  
  9. raw_output
  10. 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.
  11.  
  12. Return Values ¶
  13. Returns the hash as a 32-character hexadecimal number.
  14.  
  15. Examples ¶
  16. Example #1 A md5() example
  17.  
  18. <?php
  19. $str = 'apple';
  20.  
  21. if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
  22. echo "Would you like a green or red apple?";
  23. }
  24. ?>
  25. See Also ¶
  26. md5_file() - Calculates the md5 hash of a given file
  27. sha1_file() - Calculate the sha1 hash of a file
  28. crc32() - Calculates the crc32 polynomial of a string
  29. sha1() - Calculate the sha1 hash of a string
  30. hash() - Generate a hash value (message digest)
  31. crypt() - One-way string hashing
  32. password_hash() - Creates a password hash
  33. add a note add a note
  34. User Contributed Notes 13 notes
  35. up
  36. down
  37. 10 radon8472 at radon-software dot net ¶2 years ago
  38. <?php
  39. function raw2hex($rawBinaryChars)
  40. {
  41. return = array_pop(unpack('H*', $rawBinaryChars));
  42. }
  43. ?>
  44.  
  45. The complement of hey2raw.
  46. You can use to convert from raw md5-format to human-readable format.
  47.  
  48. This can be usefull to check "Content-Md5" HTTP-Header.
  49.  
  50. <?php
  51. $rawMd5 = base64_decode($_SERVER['HTTP_CONTENT_MD5']);
  52. $post_data = file_get_contents("php://input");
  53.  
  54. if(raw2hex($rawMd5) == md5($post_data)) // Post-Data is okay
  55. else // Post-Data is currupted
  56. ?>
  57. up
  58. down
  59. 3 Some ONE ¶11 months ago
  60. speed of hash('md5',) VS md5()
  61.  
  62. 2017-07-14, on a i7-3540M CPU @ 3.00GHz, md5() is slightly quicker than hash('md5',)
  63. This code takes 2.29 seconds
  64. <?php
  65. for($i=0;$i<10000000;++$i) md5("$i");
  66. ?>
  67.  
  68. while this one takes 2.77 seconds
  69. <?php
  70. for($i=0;$i<10000000;++$i) hash('md5',"$i");
  71. ?>
  72.  
  73. 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