From d7605dd6adf624e76eb644d7eae4e5e855dfc672 Mon Sep 17 00:00:00 2001 From: Matt Mullenweg Date: Wed, 19 Oct 2005 06:09:23 +0000 Subject: [PATCH] Fix for header redirects - Hat tip: http://www.davidmeade.com/post/post.php?topicID=579 git-svn-id: https://develop.svn.wordpress.org/trunk@2956 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/functions.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index c30f38a025..ad54d26fef 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -925,9 +925,13 @@ function do_enclose( $content, $post_ID ) { endforeach; } -function wp_get_http_headers( $url ) { +function wp_get_http_headers( $url, $red = 1 ) { global $wp_version; @set_time_limit( 60 ); + + if ( $red > 5 ) + return false; + $parts = parse_url( $url ); $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : ''); $host = $parts['host']; @@ -952,6 +956,13 @@ function wp_get_http_headers( $url ) { $headers["$key"] = $matches[2][$i]; } + $code = preg_replace('/.*?(\d{3}).*/i', '$1', $response); + + $headers['status_code'] = $code; + + if ( '302' == $code || '301' == $code ) + return wp_get_http_headers( $url, ++$red ); + preg_match('/.*([0-9]{3}).*/', $response, $return); $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404 return $headers;