md5()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

md5()

Post by guitarlvr »

If you run the md5() function on a file, will it return a unique 32 bit hash for that file or is there a posibility that it would be the same if you edited the same file and added a space, let alone a completely different file?

Wayne
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

If you change anything within the file it will return a different hash, and you should be using md5_file() for files
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

Thats exactly what i need. Thanks.

Wayne
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Jcart is wrong. There is a chance that an md5 hash could be the same for two distinct files. It's incredibly unlikely of course, but it is possible.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I never said there isn't a chance for a collision :?, although I worded my reply kind of weird so I understand why you would "correct me"
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

if two files were exactly the same they would return the same hash, correct?

Wayne
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Try it.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Jcart wrote:I never said there isn't a chance for a collision :?, although I worded my reply kind of weird so I understand why you would "correct me"
You said: "If you change anything within the file it will return a different hash". That's not true. There is a very, very small chance that it will return the same hash.
Post Reply