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?
[SOLVED]Why does md5 return different hash code
Moderator: General Moderators
[SOLVED]Why does md5 return different hash code
Last edited by tralli10 on Mon Sep 26, 2011 3:53 pm, edited 1 time in total.
Re: Why does md5 return different hash code for same values?
Any examples? Have you tried var_dump($url)?
Re: Why does md5 return different hash code for same values?
I did but it returns the same url as echo i.e:Celauran wrote:Any examples? Have you tried var_dump($url)?
[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?
Ofcourse! each ampersand in $url was infact '$amp;' but the browser converted it to '&' before I could see it. htmlspecialchars_decode($url) fixed that.