diff -up ./modules/openid/openid.inc ./modules/openid/openid.inc
--- ./modules/openid/openid.inc	2009-05-21 02:42:09.000000000 -0700
+++ ./modules/openid/openid.inc	2009-05-21 12:12:32.000000000 -0700
@@ -191,23 +191,43 @@ function _openid_nonce() {
  */
 function _openid_link_href($rel, $html) {
   $rel = preg_quote($rel);
-  preg_match('|<link\s+rel=["\'](.*)'. $rel .'(.*)["\'](.*)/?>|iUs', $html, $matches);
-  if (isset($matches[3])) {
-    preg_match('|href=["\']([^"]+)["\']|iU', $matches[3], $href);
-    return trim($href[1]);
+  
+  // find all link tags
+  preg_match_all('|<link([^>]*)>|iUs', $html, $matcharray);
+  // loop over each and find the first one with the right "rel"
+  foreach ($matcharray[1] as $linkguts) {
+    // does this contain the right "rel" value?
+    preg_match('|rel\s*=\s*["\'](([^"\']*)' . $rel . '([^"\']*))["\']|iUs', $linkguts, $relmatches);
+    if ($relmatches[1]) {
+      // we have the correct "rel", now find the href value
+      preg_match('|href\s*=\s*["\']([^"\']*)["\']|iUs', $linkguts, $hrefmatches);
+      if ($hrefmatches[1]) {
+        return $hrefmatches[1];
+      }
+    }
   }
+  
   return FALSE;
 }
 
 /**
- * Pull the http-equiv attribute out of an html meta element
+ * Pull the content attribute out of the html meta element with the indicated http-equiv
  */
 function _openid_meta_httpequiv($equiv, $html) {
-  preg_match('|<meta\s+http-equiv=["\']'. $equiv .'["\'](.*)/?>|iUs', $html, $matches);
-  if (isset($matches[1])) {
-    preg_match('|content=["\']([^"]+)["\']|iUs', $matches[1], $content);
-    if (isset($content[1])) {
-      return $content[1];
+  $equiv = preg_quote($equiv);
+  
+  // find all meta tags
+  preg_match_all('|<meta([^>]*)>|iUs', $html, $matcharray);
+  // loop over each and find the first one with the right "http-equiv"
+  foreach ($matcharray[1] as $metaguts) {
+    // does this contain the right "http-equiv" value?
+    preg_match('|http-equiv\s*=\s*["\'](\s*' . $equiv . '\s*)["\']|iUs', $metaguts, $httpequivmatches);
+    if ($httpequivmatches[1]) {
+      // we have the correct "http-equiv", now find the content value
+      preg_match('|content\s*=\s*["\']([^"\']*)["\']|iUs', $metaguts, $contentmatches);
+      if ($contentmatches[1]) {
+        return $contentmatches[1];
+      }
     }
   }
   return FALSE;
