public static function timingSafeEquals($safe, $user)
	{
		// Use builtin has comparison function available when running on PHP 5.6+
		if(function_exists('hash_equals'))
		{
			return hash_equals((string)$safe, (string)$user);
		}
		
		$safe .= chr(0);
		$user .= chr(0);

		$safeLen = strlen($safe);
		$userLen = strlen($user);
		$result = $safeLen - $userLen;

		for($i = 0; $i < $userLen; $i++)
		{
			$result |= (ord($safe[$i % $safeLen]) ^ ord($user[$i]));
		}

		return $result === 0;
	}
public static function timingSafeEquals($safe, $user)
	{
		// Use builtin has comparison function available when running on PHP 5.6+
		if(function_exists('hash_equals'))
		{
			return hash_equals((string)$safe, (string)$user);
		}
		
		$safe .= chr(0);
		$user .= chr(0);

		$safeLen = strlen($safe);
		$userLen = strlen($user);
		$result = $safeLen - $userLen;

		for($i = 0; $i < $userLen; $i++)
		{
			$result |= (ord($safe[$i % $safeLen]) ^ ord($user[$i]));
		}

		return $result === 0;
	}
public static function timingSafeEquals ( $ safe , $ user ) { // Use builtin has comparison function available when running on PHP 5.6+ if ( function_exists ( 'hash_equals' ) ) { return hash_equals ( ( string ) $ safe , ( string ) $ user ) ; } $ safe .= chr ( 0 ) ; $ user .= chr ( 0 ) ; $ safeLen = strlen ( $ safe ) ; $ userLen = strlen ( $ user ) ; $ result = $ safeLen - $ userLen ; for ( $ i = 0 ; $ i < $ userLen ; $ i ++ ) { $ result |= ( ord ( $ safe [ $ i % $ safeLen ] ) ^ ord ( $ user [ $ i ] ) ) ; } return $ result === 0 ; }
Perform a timing-safe string comparison.

@param string $safe Safe string value.
@param string $user User-supplied value for comparsion.
@return boolean
Perform a timing - safe string comparison .