This is working great on 2.7.1. One thing I had to do to get it to work though was to remove the following line from the OP code:
$hostname = str_replace(’www.’, ”, $hostname);
It was causing errors but after removing it, everything works flawlessly. I have 3 domains all pointing to the same blog and I can login and/or read any page or post using any of the domain names.