array( 'max_redirects' => 5, // allows 4 redirects :/ 'timeout' => 5, ) )); $fp = @fopen($url, 'r', false, $ctx); $ret['success'] = false; if (! $fp) { return $ret; } $ret['locations'] = array(); $ret['metaData'] = stream_get_meta_data($fp); fclose($fp); // analyze HTTP headers foreach ($ret['metaData']['wrapper_data'] as $line) { if (preg_match('@^Location: (.*)$@i', $line, $m)) { if ($m[1][0] === '/') { // root-relative URI $m[1] = $root . $m[1]; } elseif (strpos($m[1], '://') >= 4) { // full URL $root = _getRoot($m[1]); } $ret['locations'][] = $m[1]; } if (preg_match('@^HTTP/1\\.[01] 200@i', $line, $m)) { $ret['success'] = true; } } return $ret; } function _getRoot($url) { list($proto, $url) = explode('://', $url, 2); list($host) = explode('/', $url, 2); return $proto . '://' . $host; } ?>