Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7987767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:14:37+00:00 2026-06-04T12:14:37+00:00

If I do: <?php echo md5(file_get_contents(/path/to/file)) ?> …will this always produce the same hash

  • 0

If I do:

<?php echo md5(file_get_contents("/path/to/file")) ?>

…will this always produce the same hash as:

<?php echo md5_file("/path/to/file") ?>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:14:38+00:00Added an answer on June 4, 2026 at 12:14 pm

    Yes they return the same:

    var_dump(md5(file_get_contents(__FILE__)));
    var_dump(md5_file(__FILE__));
    

    which returns this in my case:

    string(32) "4d2aec3ae83694513cb9bde0617deeea"
    string(32) "4d2aec3ae83694513cb9bde0617deeea"
    

    Edit:
    Take a look at the source code of both functions: https://github.com/php/php-src/blob/master/ext/standard/md5.c (Line 47 & 76). They both use the same functions to generate the hash except that the md5_file() function opens the file first.

    2nd Edit:
    Basically the md5_file() function generates the hash based on the file contents, not on the file meta data like the filename. This is the same way md5sum on Linux systems work.
    See this example:

    pr@testumgebung:~# echo foobar > foo.txt
    pr@testumgebung:~# md5sum foo.txt
    14758f1afd44c09b7992073ccf00b43d  foo.txt
    pr@testumgebung:~# mv foo.txt bar.txt
    pr@testumgebung:~# md5sum bar.txt
    14758f1afd44c09b7992073ccf00b43d  bar.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Will the MD5 cryptographic hash function output be same in all programming
For example… This PHP code <?php echo '<html>'; echo '<body>'; echo '<h1>Header One</h1>'; echo
I use <?php echo __("this is my string"); ?> inside my views to display
$.post('includes/script.php', $(this).serialize(), function(data) { $('body').append(data); }); alert ($('#new').length) php script is <php echo <div
When I pass this line echo -n aWord | md5 directly in shell I
my captcha field <p style=height:30px;><img id=captcha src=includes/secureimage/securimage_show.php?sid=<?php echo md5(time()); ?> alt=CAPTCHA Image /> <a
PHP Echo or Print functions does not show anything when php is busy with
PHP echo function is not outputing strings in the format of html tag like
Given hello.php: <?php echo Hello; ?> rendering the page works fine and returns Hello
How do I echo a forwardslash / ? echo <?php echo $_SERVER['HTTP_HOST'] ?> .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.