summaryrefslogtreecommitdiff
path: root/url.class
diff options
context:
space:
mode:
Diffstat (limited to 'url.class')
-rw-r--r--url.class6
1 files 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];