1

My webhost doesn't allow usage of PHP 5.5.9 and I need to use the hash_equals() function.

Is there any alternative to this?

1
  • 1
    The user contributed note by asphp at dsgml dot com on the hash_equals() PHP Docs page provides code that can be used with earlier versions of PHP Commented Sep 19, 2015 at 18:44

1 Answer 1

6

Maybe try:

if(!function_exists('hash_equals')) { function hash_equals($str1, $str2) { if(strlen($str1) != strlen($str2)) { return false; } else { $res = $str1 ^ $str2; $ret = 0; for($i = strlen($res) - 1; $i >= 0; $i--) $ret |= ord($res[$i]); return !$ret; } } } 

Code from: asphp at dsgml dot com

Copied from the PHP comments.

Sign up to request clarification or add additional context in comments.

5 Comments

Maybe you want to say from where you have this: php.net/manual/en/function.hash-equals.php#115635
Remember to cite where you copied the code from, unless you are the original author.
Sure, sorry for that. I changed comment and added information where user can see original post.
@Erminesoft Shouldn't it be if(function_exists) (without !)? Seems to me now it says, if function hash_equals does not exists, do hash_equals, else...
The comment is removed from PHP site. Is the function actually correct?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.