Page 1 of 1

[SOLVED]Why does md5 return different hash code

Posted: Mon Sep 26, 2011 1:05 pm
by tralli10
Hi I am having trouble understanding this behavior. I'm using a cms system called cms made simple (I've tried posting on their forum but get no replies). One of it's addons has a function that creates an url (it's inner workings is unknown to me, but I know it returns an url string). Lets say I call the function and it returns the url: http://someurl.com and store it in $url, now when I call md5($url) it returns invalid hash code but when I echo $url and copy/paste the string into md5: md5("http://someurl.com") it returns the expected hash value.
Now how could this be? At first I suspected encoding problems, but I've tried utf8_encode, utf8_decode, urlencode, urldecode, rawurlencode even htmlentitites, stripslashes, addslashes on $url but I don't get the correct hashcode as from "http://someurl.com"

Any ideas?

Re: Why does md5 return different hash code for same values?

Posted: Mon Sep 26, 2011 1:09 pm
by Celauran
Any examples? Have you tried var_dump($url)?

Re: Why does md5 return different hash code for same values?

Posted: Mon Sep 26, 2011 3:38 pm
by tralli10
Celauran wrote:Any examples? Have you tried var_dump($url)?
I did but it returns the same url as echo i.e:
[text]string(116) "http://vintage.is.hysir.net/index.php?m ... 31&page=31" [/text]

But when I copied the url into another variable $foo and dump both strings it shows some interesting results:
[text]
string(108) "http://vintage.is.hysir.net/index.php?m ... 31&page=31"
string(116) "http://vintage.is.hysir.net/index.php?m ... 31&page=31"
[/text]

$url length is 116 while $foo is 108

Re: Why does md5 return different hash code for same values?

Posted: Mon Sep 26, 2011 3:52 pm
by tralli10
Ofcourse! each ampersand in $url was infact '$amp;' but the browser converted it to '&' before I could see it. htmlspecialchars_decode($url) fixed that.