From 624d83ee186b03ea720a785fc463c381db9ea451 Mon Sep 17 00:00:00 2001 From: Thomas BrĂ¼derli Date: Wed, 18 Apr 2007 07:38:11 +0000 Subject: Unset host header otherwise redirects to other hosts fail; Avoid infinite redirect loops --- url.class | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/url.class b/url.class index bdad756..7f9cfb3 100644 --- a/url.class +++ b/url.class @@ -34,6 +34,7 @@ class it_url var $headers; /* Headers of page fetched by get() */ var $data; /* Data part, even if return code is not 200 */ var $result; /* Return code of get() */ + var $redir = 0; /* Redirect count */ /** @@ -275,9 +276,10 @@ function get($p=null, $timeout=5000) $url->headers[$parts[1]] = $url->result = $parts[2]; elseif (preg_match('#^Location: (https?://[^/]*)?(/)?(.*)$#', $line, $parts) && ($parts[1] != $url->url)) # Handle redirects (supports relative and global) { - unset($p['url']); + unset($p['url'], $p['headers']['Host']); $url->it_url($parts[1] ? $parts[1].$parts[2].$parts[3] : $url->protocol.'://'.$url->realhostname.($parts[2] ? $parts[2].$parts[3] : '/'.dirname($url->path).'/'.$parts[3])); - return $url->get($p); + if (++$url->redir <= 4) /* Avoid infinite redirects */ + return $url->get($p); } elseif (preg_match('#^([^:]+): (.*)$#', $line, $parts)) $url->headers[$parts[1]] = $parts[2]; -- cgit v1.2.3